@@ -615,24 +615,6 @@ def main():
615615 '(ADDED POST-PROCESSING) vertical coordinate sigma value'
616616 )
617617 DS ['bk' ].attrs ['units' ] = ('None' )
618-
619- # Handle vertical flipping for OpenMars
620- if DS [model .pfull ].values [0 ] != DS [model .pfull ].values .min ():
621- # Flip only variables that actually have the lev dimension
622- for var_name in list (DS .data_vars .keys ()):
623- if model .dim_pfull in DS [var_name ].dims :
624- DS [var_name ] = DS [var_name ].isel (** {model .dim_pfull : slice (None , None , - 1 )})
625- # Also flip the coordinate itself
626- DS = DS .isel (** {model .dim_pfull : slice (None , None , - 1 )})
627- # Flip phalf dimension if it exists
628- if model .dim_phalf in DS .dims :
629- for var_name in list (DS .data_vars .keys ()):
630- if model .dim_phalf in DS [var_name ].dims :
631- DS [var_name ] = DS [var_name ].isel (** {model .dim_phalf : slice (None , None , - 1 )})
632- DS = DS .isel (** {model .dim_phalf : slice (None , None , - 1 )})
633- DS .attrs ['vertical_dimension_flipped' ] = True
634- print (f"{ Red } NOTE: all variables flipped along vertical dimension. "
635- f"Top of the atmosphere is now index = 0" )
636618
637619 # --------------------------------------------------------------
638620 # Emars Processing
@@ -819,15 +801,31 @@ def main():
819801 if model_type == 'pcm' and 'vertical_dimension_flipped' in DS .attrs :
820802 print (f"{ Cyan } Using PCM-specific vertical orientation handling" )
821803 # Skip automatic flipping - we've already handled it in PCM processing
822- elif model_type == 'openmars' and 'vertical_dimension_flipped' in DS .attrs :
823- print (f"{ Cyan } Using OpenMars-specific vertical orientation handling" )
824- # Skip automatic flipping - we've already handled it in OpenMars processing
825804 else :
826- # Standard vertical processing for other models
805+ # # Standard vertical processing for other models
806+ # if DS[model.pfull].values[0] != DS[model.pfull].values.min():
807+ # DS = DS.isel(**{model.dim_pfull: slice(None, None, -1)})
808+ # # Flip phalf, ak, bk:
809+ # DS = DS.isel(**{model.dim_phalf: slice(None, None, -1)})
810+ # print(f"{Red}NOTE: all variables flipped along vertical dimension. "
811+ # f"Top of the atmosphere is now index = 0")
812+
813+ # Standard vertical processing for all models
827814 if DS [model .pfull ].values [0 ] != DS [model .pfull ].values .min ():
815+ # Collect flipped variables to avoid in-place modification issues
816+ flipped_vars = {}
817+ for var_name in list (DS .data_vars .keys ()):
818+ if model .dim_pfull in DS [var_name ].dims :
819+ flipped_vars [var_name ] = DS [var_name ].isel (** {model .dim_pfull : slice (None , None , - 1 )})
820+
821+ # Apply all flips at once
822+ for var_name , flipped_var in flipped_vars .items ():
823+ DS [var_name ] = flipped_var
824+
825+ # Flip the coordinate dimensions
828826 DS = DS .isel (** {model .dim_pfull : slice (None , None , - 1 )})
829- # Flip phalf, ak, bk:
830827 DS = DS .isel (** {model .dim_phalf : slice (None , None , - 1 )})
828+
831829 print (f"{ Red } NOTE: all variables flipped along vertical dimension. "
832830 f"Top of the atmosphere is now index = 0" )
833831
0 commit comments