Skip to content

Commit

Permalink
Update CICE plotting tools. Add ciceplots.csh and ciceplots2d.py. (#958)
Browse files Browse the repository at this point in the history
Update CICE plotting tools. Add ciceplots.csh and ciceplots2d.py. Update timeseries.py. Remove timeseries.csh. Have the plotting tools copied into case directories. Update documentation. ciceplots2d.py generates global and polar plots for fields on CICE history files. ciceplots.csh is a general script that calls timeseries.py and ciceplots2d.py to generate plots for a user defined case. Add basemap to the cice conda environment.yml file to support the plotting packages.

Add output to JRA55_files in ice_forcing.F90 to make it easier to understand when/why JRA55 files are missing.

Add NO_CDF5 CPP to izumi_nag Macros file.

Change 10 year production test case to 8 year test. This will serve as basis for release results.

Update Icepack to #083d6e3cf42198 from May 28, 2024. Includes updates to Icepack plotting tools.
  • Loading branch information
apcraig committed May 31, 2024
1 parent 44c5998 commit 2771786
Show file tree
Hide file tree
Showing 13 changed files with 323 additions and 240 deletions.
2 changes: 1 addition & 1 deletion cice.setup
Original file line number Diff line number Diff line change
Expand Up @@ -838,7 +838,7 @@ EOF
endif
# from basic script dir to case
foreach file (cice.build cice.settings Makefile ice_in makdep.c setup_run_dirs.csh timeseries.csh timeseries.py)
foreach file (cice.build cice.settings Makefile ice_in makdep.c setup_run_dirs.csh ciceplots.csh ciceplots2d.py timeseries.py)
if !(-e ${ICE_SCRIPTS}/$file) then
echo "${0}: ERROR, ${ICE_SCRIPTS}/$file not found"
exit -1
Expand Down
3 changes: 3 additions & 0 deletions cicecore/cicedyn/general/ice_forcing.F90
Original file line number Diff line number Diff line change
Expand Up @@ -2276,6 +2276,9 @@ subroutine JRA55_files(yr)
enddo

if (.not.exists) then
write(nu_diag,*) subname,' atm_data_dir = ',trim(atm_data_dir)
write(nu_diag,*) subname,' atm_data_type_prefix = ',trim(atm_data_type_prefix)
write(nu_diag,*) subname,' atm_data_version = ',trim(atm_data_version)
call abort_ice(error_message=subname//' could not find forcing file')
endif

Expand Down
56 changes: 56 additions & 0 deletions configuration/scripts/ciceplots.csh
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#!/bin/csh -f

source ${MODULESHOME}/init/csh

# User defined stuff
# Set case and case directory
# Set files, notes, fstr, and fields

set case = "CICE6.5.1"
set casedir = "/glade/derecho/scratch/tcraig/CICE_RUNS/cgx1proda"

# setup plots

set histdir = "${casedir}/history"

set files = ("${histdir}/iceh.2012-03.nc" \
"${histdir}/iceh.2012-09.nc" )
set notes = ("2012 March Mean" \
"2012 Sept Mean" )
set fstrs = ("Mar12" \
"Sep12" )

set fields = ("aice" "hi" "hs")

#conda config --add channels conda-forge
#conda config --set channel_priority strict
#conda search basemap --channel conda-forge
#conda create -p /glade/u/home/tcraig/conda/envs/basemap -c conda-forge basemap=1.4.1 basemap-data basemap-data-hires netCDF4

module load conda
source ${NCAR_ROOT_CONDA}/etc/profile.d/conda.csh

conda activate /glade/u/home/tcraig/conda/envs/basemap

echo " "
echo " "

echo ./timeseries.py \"${casedir}\" --case \"${case}\" --grid
./timeseries.py "${casedir}" --case "${case}" --grid

echo " "

set cnt = 0
while ($cnt < ${#files})
@ cnt = $cnt + 1
set file = "${files[$cnt]}"
set note = "${notes[$cnt]}"
set fstr = "${fstrs[$cnt]}"
foreach field ($fields)
echo ./ciceplots2d.py \"$field\" \"$file\" \"$case\" \"$note\" \"$fstr\"
./ciceplots2d.py "$field" "$file" "$case" "$note" "$fstr"
end
end

echo "DONE"

148 changes: 148 additions & 0 deletions configuration/scripts/ciceplots2d.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
#!/usr/bin/env python3

#Importing the necessary libraries
import sys
import os
import numpy as np
from netCDF4 import Dataset
import matplotlib as mpl
import matplotlib.pyplot as plt
from mpl_toolkits.basemap import Basemap

if len(sys.argv) != 6:
print("ciceplots.py requires 5 arguments")
print(" 1. field name in file, ie. \"aice\"")
print(" 2. cice history file full path, ie. \"/glade/scratch/user/case/history/iceh.2012-03.nc\"")
print(" 3. case name, used to annotate plot, ie. \"CICE6.5.1\"")
print(" 4. notes, used to annotate plot, ie. 2012 \"March Mean\"")
print(" 5. file string, use to create unique png filenames, ie. \"Mar12\"")
quit()

field = sys.argv[1]
pathf = sys.argv[2]
casen = sys.argv[3]
notes = sys.argv[4]
fstr = sys.argv[5]
fname = os.path.basename(pathf)
title = field + " " + notes
cfnam = casen + " " + fname
#print("field = ",field)
#print("pathf = ",pathf)
#print("casen = ",casen)
#print("notes = ",notes)
#print("fname = ",fname)
#print("title = ",title)
#print("cfnam = ",cfnam)

#Reading the netCDF file
data = Dataset(pathf,'r')
#print (data)

lons = data.variables['TLON'][:,:]
lats = data.variables['TLAT'][:,:]
var1 = data.variables[field][:,:,:]
var1 = var1[0,:,:]
var1[ var1==0.00 ] = np.nan
#mask = data.variables['tmask'][:,:]
#mask[ mask>0.5 ] = np.nan

#print("lons.shape = ",lons.shape)
#print("var1.shape = ",var1.shape)

# Lon/Lat Projection

#print("Plot global")
#m = Basemap(projection='cyl',llcrnrlat=-90,urcrnrlat=90,
# llcrnrlon=0,urcrnrlon=360,resolution='c')
m = Basemap(projection='cyl',llcrnrlat=-90,urcrnrlat=90,
llcrnrlon=0,urcrnrlon=360,resolution='l')
fig, ax = plt.subplots()
#plt.figure(figsize=(6,4))
m.drawcoastlines(linewidth=0.2)
m.fillcontinents(color='black',lake_color='white')
#draw parallels and meridians.
m.drawparallels(np.arange(-60.,61.,30.),labels=[1,0,0,0])
m.drawmeridians(np.arange(0.,361.,45.),labels=[1,0,0,1])
#draw map boundary
m.drawmapboundary(fill_color='white')
#setting colorbar
cmap = plt.get_cmap('jet')
barticks = None
norm = "linear"
if field in ['hi']:
bounds = np.arange(0,2.05,0.1)
bounds = np.append(bounds,[2.25,2.5,2.75,3.0,3.25,3.5,3.75,4.0])
norm = mpl.colors.BoundaryNorm(bounds,cmap.N,extend='max')
barticks=[0,0.5,1.0,1.5,2.0,2.5,3.0,3.5,4.0]
if field in ['hs']:
bounds = np.arange(0,1.02,0.05)
bounds = np.append(bounds,[1.5,2.0,2.5,3.0,3.5,4.0])
norm = mpl.colors.BoundaryNorm(bounds,cmap.N,extend='max')
barticks=[0,0.25,0.5,0.75,1.0,2.0,3.0,4.0]
#matplotlib scatter-plot
m.scatter(lons,lats,c=var1,cmap=cmap,marker='o',s=0.2,norm=norm)
m.colorbar(label=field, ticks=barticks)
plt.rcParams["figure.dpi"] = 300
plt.title(title)
plt.text(x=0.0,y=-0.1,s=cfnam,transform=ax.transAxes,horizontalalignment='left',verticalalignment='top',fontsize='x-small')
oname = field + "_gl_" + fstr + ".png"
print('Saving file to ',oname)
plt.savefig(oname)
#plt.show()
plt.close()

# North Polar Stereographic Projection

#print("Plot NH")
#m = Basemap(projection='npstere',boundinglat=45,lon_0=-45,resolution='c')
m = Basemap(projection='npstere',boundinglat=45,lon_0=-45,resolution='l')
fig, ax = plt.subplots()
#plt.figure(figsize=(6,4))
m.drawcoastlines(linewidth=0.2)
m.fillcontinents(color='black',lake_color='white')
# draw parallels and meridians.
m.drawparallels(np.arange(-60.,61.,30.),labels=[0,0,0,0])
m.drawmeridians(np.arange(0.,361.,45.),labels=[0,0,0,0])
m.drawmapboundary(fill_color='white')
#setting colorbar (set above)
m.scatter(lons,lats,c=var1,cmap=cmap,marker='o',s=0.2,latlon=True,norm=norm)
#m.colorbar(label=field)
m.colorbar(label=field, ticks=barticks)
plt.rcParams["figure.dpi"] = 300
plt.title (title)
plt.text(x=0.0,y=-0.02,s=cfnam,transform=ax.transAxes,horizontalalignment='left',verticalalignment='top',fontsize='x-small')
oname = field + "_nh_" + fstr + ".png"
print('Saving file to ',oname)
plt.savefig(oname)
#plt.show()
plt.close()

# South Polar Stereographic Projection

#print("Plot SH")
#m = Basemap(projection='npstere',boundinglat=45,lon_0=-45,resolution='c')
m = Basemap(projection='spstere',boundinglat=-45,lon_0=180,resolution='l')
fig, ax = plt.subplots()
#plt.figure(figsize=(6,4))
m.drawcoastlines(linewidth=0.2)
m.fillcontinents(color='black',lake_color='white')
# draw parallels and meridians.
m.drawparallels(np.arange(-60.,61.,30.),labels=[0,0,0,0])
m.drawmeridians(np.arange(0.,361.,45.),labels=[0,0,0,0])
m.drawmapboundary(fill_color='white')
#setting colorbar (set above)
m.scatter(lons,lats,c=var1,cmap=cmap,marker='o',s=0.2,latlon=True,norm=norm)
#m.colorbar(label=field)
m.colorbar(label=field, ticks=barticks)
plt.rcParams["figure.dpi"] = 300
plt.title (title)
plt.text(x=0.0,y=-0.02,s=cfnam,transform=ax.transAxes,horizontalalignment='left',verticalalignment='top',fontsize='x-small')
oname = field + "_sh_" + fstr + ".png"
print('Saving file to ',oname)
plt.savefig(oname)
#plt.show()
plt.close()

#print("Done")
quit()

2 changes: 1 addition & 1 deletion configuration/scripts/machines/Macros.izumi_nag
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#==============================================================================

CPP := /usr/bin/cpp
CPPDEFS := -DFORTRANUNDERSCORE -DNO_R16 $(ICE_CPPDEFS)
CPPDEFS := -DFORTRANUNDERSCORE -DNO_R16 -DNO_CDF5 $(ICE_CPPDEFS)
CFLAGS := -c

FIXEDFLAGS := -fixed
Expand Down
3 changes: 3 additions & 0 deletions configuration/scripts/machines/environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ dependencies:
- matplotlib-base
- cartopy
- netcdf4
- basemap=1.4.1
- basemap-data
- basemap-data-hires
# Python dependencies for building the HTML documentation
- sphinx
- sphinxcontrib-bibtex
7 changes: 7 additions & 0 deletions configuration/scripts/options/set_nml.run8year
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
npt_unit = 'y'
npt = 8
dumpfreq = 'y'
dumpfreq_n = 1
diagfreq = 24
histfreq = 'm','x','x','x','x'

2 changes: 1 addition & 1 deletion configuration/scripts/tests/prod_suite.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Test Grid PEs Sets BFB-compare
qcchk gx3 72x1 qc,qcchk,medium qcchk_gx3_72x1_medium_qc_qcchk
qcchk gx1 144x1 qc,qcchk,medium
smoke gx1 144x2 gx1prod,long,run10year
smoke gx1 128x2 gx1prod,long,run8year
qcchk gx3 72x1 qc,qcchkf,medium,alt02 qcchk_gx3_72x1_medium_qc_qcchk
qcchk gx3 72x1 qc,qcchk,dt3456s,medium qcchk_gx3_72x1_medium_qc_qcchk
129 changes: 0 additions & 129 deletions configuration/scripts/timeseries.csh

This file was deleted.

Loading

0 comments on commit 2771786

Please sign in to comment.