Skip to content

Commit

Permalink
Replace CDAT
Browse files Browse the repository at this point in the history
  • Loading branch information
forsyth2 committed Oct 3, 2023
1 parent dadaadc commit 3718f14
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 8 deletions.
15 changes: 15 additions & 0 deletions zppy/templates/cdscan_replacement.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import sys

import xcdat


def cdscan_replacement(output_file, input_files):
dataset = xcdat.open_mfdataset(input_files)
# TODO: write to xml, not netCDF
dataset.to_netcdf(output_file)


if __name__ == "__main__":
output_file = sys.argv[1]
input_files = sys.argv[2:]
cdscan_replacement(output_file, input_files)
4 changes: 2 additions & 2 deletions zppy/templates/e3sm_diags.bash
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ create_links_ts()
# xml file will cover the whole period from year1 to year2
xml_name=${v}_${begin_year}01_${end_year}12.xml
export CDMS_NO_MPI=true
cdscan -x ${xml_name} -f ${v}_files.txt
python cdscan_replacement.py ${xml_name} ${v}_files.txt
if [ $? != 0 ]; then
cd {{ scriptDir }}
echo "ERROR (${error_num})" > {{ prefix }}.status
Expand All @@ -129,7 +129,7 @@ create_links_ts_rof()
cd ${ts_rof_dir_destination}
v="RIVER_DISCHARGE_OVER_LAND_LIQ"
xml_name=${v}_${begin_year}01_${end_year}12.xml
cdscan -x ${xml_name} ${ts_rof_dir_source}/${v}_*.nc
python cdscan_replacement.py ${xml_name} ${ts_rof_dir_source}/${v}_*.nc
if [ $? != 0 ]; then
cd {{ scriptDir }}
echo "ERROR (${error_num})" > {{ prefix }}.status
Expand Down
4 changes: 2 additions & 2 deletions zppy/templates/global_time_series.bash
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ atmosphere_only=${atmosphere_only,,}
echo 'Create xml files for atm'
export CDMS_NO_MPI=true
cd ${case_dir}/post/atm/glb/ts/monthly/${ts_num_years}yr
cdscan -x glb.xml *.nc
python cdscan_replacement.py glb.xml *.nc
if [ $? != 0 ]; then
cd {{ scriptDir }}
echo 'ERROR (1)' > {{ prefix }}.status
Expand All @@ -67,7 +67,7 @@ if [[ ${atmosphere_only} == "false" ]]; then
echo 'Create xml for for ocn'
export CDMS_NO_MPI=true
cd ${case_dir}/post/ocn/glb/ts/monthly/${ts_num_years}yr
cdscan -x glb.xml mpaso.glb*.nc
python cdscan_replacement.py glb.xml mpaso.glb*.nc
if [ $? != 0 ]; then
cd {{ scriptDir }}
echo 'ERROR (3)' > {{ prefix }}.status
Expand Down
7 changes: 3 additions & 4 deletions zppy/templates/readTS.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import cdms2
import cdutil
import xcdat


class TS(object):
def __init__(self, filename):

self.filename = filename

self.f = cdms2.open(filename)
self.f = xcdat.open_dataset(filename)

def __del__(self):

Expand Down Expand Up @@ -62,6 +61,6 @@ def globalAnnual(self, var):
v = self.f(var)

# Annual average
v = cdutil.YEAR(v)
v = self.f.temporal.group_average(v, "year")

return v

0 comments on commit 3718f14

Please sign in to comment.