Skip to content

Commit 856daaa

Browse files
committed
reverting marsformat, starting over debugging
1 parent ab2b940 commit 856daaa

1 file changed

Lines changed: 16 additions & 34 deletions

File tree

bin/MarsFormat.py

Lines changed: 16 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -574,22 +574,12 @@ def main():
574574
lat = DS[model.dim_lat] # Replace DS.lat
575575
lon = DS[model.dim_lon]
576576

577-
# Create pfull as a coordinate variable with values (will become the new dimension)
578-
pfull_values = DS[model.dim_pfull] * ref_press
579-
DS = DS.assign_coords(pfull=('lev', pfull_values.values))
580-
581-
# Now swap the 'lev' dimension with 'pfull' coordinate throughout the dataset
582-
DS = DS.swap_dims({'lev': 'pfull'})
583-
584-
# Drop the old 'lev' coordinate if it still exists
585-
if 'lev' in DS.coords:
586-
DS = DS.drop_vars('lev')
587-
588-
# **ADD THIS LINE:**
589-
model.dim_pfull = 'pfull' # Update model to use new dimension name
590-
591-
DS['pfull'].attrs['long_name'] = '(ADDED POST-PROCESSING) reference pressure'
592-
DS['pfull'].attrs['units'] = 'Pa'
577+
DS = DS.assign(pfull = DS[model.dim_pfull]*ref_press)
578+
579+
DS['pfull'].attrs['long_name'] = (
580+
'(ADDED POST-PROCESSING) reference pressure'
581+
)
582+
DS['pfull'].attrs['units'] = ('Pa')
593583

594584
# add ak,bk as variables
595585
# add p_half dimensions as vertical grid coordinate
@@ -599,8 +589,8 @@ def main():
599589
# needs (sigma[0] = 0, sigma[-1] = 1).
600590
# Then reorganize in the original openMars format with
601591
# (sigma[0] = 1, sigma[-1] = 0)
602-
bk = layers_mid_point_to_boundary(DS['pfull'][::-1] / ref_press, 1.)[::-1]
603-
ak = np.zeros(len(DS['pfull']) + 1)
592+
bk = layers_mid_point_to_boundary(DS[model.dim_pfull][::-1], 1.)[::-1]
593+
ak = np.zeros(len(DS[model.dim_pfull]) + 1)
604594

605595
DS[model.phalf] = (ak + ref_press*bk)
606596
DS.phalf.attrs['long_name'] = (
@@ -609,20 +599,22 @@ def main():
609599
DS.phalf.attrs['description'] = (
610600
'(ADDED POST-PROCESSING) pressure at layer interfaces'
611601
)
612-
DS.phalf.attrs['units'] = 'Pa'
602+
DS.phalf.attrs['units'] = ('Pa')
613603

614-
DS = DS.assign(bk=(model.dim_phalf, np.array(bk)))
615-
DS = DS.assign(ak=(model.dim_phalf, np.zeros(len(DS['pfull']) + 1)))
604+
DS = DS.assign(bk=(model.dim_phalf,
605+
np.array(bk)))
606+
DS = DS.assign(ak=(model.dim_phalf,
607+
np.zeros(len(DS[model.dim_pfull]) + 1)))
616608

617609
# Update Variable Description & Longname
618610
DS['ak'].attrs['long_name'] = (
619611
'(ADDED POST-PROCESSING) pressure part of the hybrid coordinate'
620612
)
621-
DS['ak'].attrs['units'] = 'Pa'
613+
DS['ak'].attrs['units'] = ('Pa')
622614
DS['bk'].attrs['long_name'] = (
623615
'(ADDED POST-PROCESSING) vertical coordinate sigma value'
624616
)
625-
DS['bk'].attrs['units'] = 'None'
617+
DS['bk'].attrs['units'] = ('None')
626618

627619
# --------------------------------------------------------------
628620
# Emars Processing
@@ -829,18 +821,8 @@ def main():
829821
if min(DS[model.dim_lon]) < 0:
830822
tmp = np.array(DS[model.dim_lon])
831823
tmp = np.where(tmp<0, tmp + 360, tmp)
832-
833-
# Create a new DataArray with the updated values and original attributes
834-
new_lon = xr.DataArray(
835-
tmp,
836-
dims=[model.dim_lon],
837-
attrs=DS[model.dim_lon].attrs.copy()
838-
)
839-
840-
# Update the coordinate properly using assign_coords
841-
DS = DS.assign_coords({model.dim_lon: new_lon})
824+
DS[model.dim_lon] = tmp
842825
DS = DS.sortby(model.dim_lon)
843-
844826
DS[model.lon].attrs['long_name'] = (
845827
'(MODIFIED POST-PROCESSING) longitude'
846828
)

0 commit comments

Comments
 (0)