Skip to content

Commit

Permalink
style fix (pre-commit)
Browse files Browse the repository at this point in the history
  • Loading branch information
lee1043 committed Nov 7, 2023
1 parent c3a6cf1 commit 5c7b40c
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 66 deletions.
12 changes: 5 additions & 7 deletions pcmdi_metrics/sea_ice/generate_sector_masks.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
default = '',
help = "Explicit path to obs monthly PR climatology")
P.add_argument("--outpd", "--outpathdata",
type = str,
type = str,
dest = 'outpathdata',
default = '/export/gleckler1/processing/metrics_package/my_test/sea_ice/git_data/',
help = "Output path for sector scale masks")
Expand Down Expand Up @@ -95,8 +95,8 @@
alist = os.listdir(area_dir) # LIST OF ALL AREACELLO FILES

for a in alist:
if string.find(a,mod) != -1:
areaf = a
if string.find(a,mod) != -1:
areaf = a
print mod,' ', a
# w = sys.stdin.readline()

Expand Down Expand Up @@ -161,9 +161,9 @@

###############################################################

sectors = ['ca','na','np','sp','sa','io']
sectors = ['ca','na','np','sp','sa','io']

for sector in sectors:
for sector in sectors:
mask = getmask(sector,lats,lons,lons_a,lons_p,land_mask)

g = cdms2.open(sec_mask_dir + 'mask_' + mod + '_' + sector + '.nc','w+')
Expand Down Expand Up @@ -193,5 +193,3 @@
print 'failed for ', mods_failed

# Calculate the Sea Ice Covered Area


2 changes: 1 addition & 1 deletion pcmdi_metrics/sea_ice/ice_area_cmip5_ssmi_reg_rms.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import cdtime, datetime
import gc

import numpy as np
import numpy as np
import pylab
import matplotlib.pyplot as plt

Expand Down
132 changes: 74 additions & 58 deletions pcmdi_metrics/sea_ice/sector_mask_defs.py
Original file line number Diff line number Diff line change
@@ -1,61 +1,77 @@
def getmask(sector,lats,lons,lons_a,lons_p,land_mask):
import MV2 as MV
#Arctic Regions
#Central Arctic
if sector == 'ca':
lat_bound1=MV.logical_and(MV.greater(lats,80.),MV.less_equal(lats,90.))
lat_bound2=MV.logical_and(MV.greater(lats,65.),MV.less_equal(lats,90.))
lon_bound1=MV.logical_and(MV.greater(lons_a,-120.),MV.less_equal(lons_a,90.))
lon_bound2=MV.logical_and(MV.greater(lons_p,90.),MV.less_equal(lons_p,240.))
reg1=MV.logical_and(lat_bound1,lon_bound1)
reg2=MV.logical_and(lat_bound2,lon_bound2)
mask=MV.where(MV.logical_or(reg1,reg2),1,0)
mask=MV.where(MV.equal(land_mask,0),0,mask) # 0 - Land

#NA region
if sector == 'na':
lat_bound=MV.logical_and(MV.greater(lats,45.),MV.less_equal(lats,80.))
lon_bound=MV.logical_and(MV.greater(lons_a,-120.),MV.less_equal(lons_a,90.))
lat_bound3=MV.logical_and(MV.greater(lats,45.),MV.less_equal(lats,50.))
lon_bound3=MV.logical_and(MV.greater(lons_a,30.),MV.less_equal(lons_a,60.))
reg3=MV.logical_and(lat_bound3,lon_bound3)

mask=MV.where(MV.logical_and(lat_bound,lon_bound),1,0)
mask=MV.where(MV.equal(reg3,True),0,mask) # Masking out the Black and Caspian Seas
mask=MV.where(MV.equal(land_mask,True),0,mask) # 0 - Land
mask=MV.where(MV.equal(land_mask,0),0,mask) # 0 - Land

#NP region
if sector == 'np':
lat_bound=MV.logical_and(MV.greater(lats,45.),MV.less_equal(lats,65.))
lon_bound=MV.logical_and(MV.greater(lons_p,90.),MV.less_equal(lons_p,240.))
mask=MV.where(MV.logical_and(lat_bound,lon_bound),1,0)
mask=MV.where(MV.equal(land_mask,0),0,mask) # 0 - Land

#Antarctic Regions

#SA region
if sector == 'sa':
lat_bound=MV.logical_and(MV.greater(lats,-90.),MV.less_equal(lats,-55.))
lon_bound=MV.logical_and(MV.greater(lons_a,-60.),MV.less_equal(lons_a,20.))
mask=MV.where(MV.logical_and(lat_bound,lon_bound),1,0)
mask=MV.where(MV.equal(land_mask,0),0,mask) # 0 - Land

#SP region
if sector == 'sp':
lat_bound=MV.logical_and(MV.greater(lats,-90.),MV.less_equal(lats,-55.))
lon_bound=MV.logical_and(MV.greater(lons_p,90.),MV.less_equal(lons_p,300.))
mask=MV.where(MV.logical_and(lat_bound,lon_bound),1,0)
mask=MV.where(MV.equal(land_mask,0),0,mask) # 0 - Land

#IO region
if sector == 'io':
lat_bound=MV.logical_and(MV.greater(lats,-90.),MV.less_equal(lats,-55.))
lon_bound=MV.logical_and(MV.greater(lons_p,20.),MV.less_equal(lons_p,90.))
mask=MV.where(MV.logical_and(lat_bound,lon_bound),1,0)
mask=MV.where(MV.equal(land_mask,0),0,mask) # 0 - Land

return mask
def getmask(sector, lats, lons, lons_a, lons_p, land_mask):
import MV2 as MV

# Arctic Regions
# Central Arctic
if sector == "ca":
lat_bound1 = MV.logical_and(MV.greater(lats, 80.0), MV.less_equal(lats, 90.0))
lat_bound2 = MV.logical_and(MV.greater(lats, 65.0), MV.less_equal(lats, 90.0))
lon_bound1 = MV.logical_and(
MV.greater(lons_a, -120.0), MV.less_equal(lons_a, 90.0)
)
lon_bound2 = MV.logical_and(
MV.greater(lons_p, 90.0), MV.less_equal(lons_p, 240.0)
)
reg1 = MV.logical_and(lat_bound1, lon_bound1)
reg2 = MV.logical_and(lat_bound2, lon_bound2)
mask = MV.where(MV.logical_or(reg1, reg2), 1, 0)
mask = MV.where(MV.equal(land_mask, 0), 0, mask) # 0 - Land

# NA region
if sector == "na":
lat_bound = MV.logical_and(MV.greater(lats, 45.0), MV.less_equal(lats, 80.0))
lon_bound = MV.logical_and(
MV.greater(lons_a, -120.0), MV.less_equal(lons_a, 90.0)
)
lat_bound3 = MV.logical_and(MV.greater(lats, 45.0), MV.less_equal(lats, 50.0))
lon_bound3 = MV.logical_and(
MV.greater(lons_a, 30.0), MV.less_equal(lons_a, 60.0)
)
reg3 = MV.logical_and(lat_bound3, lon_bound3)

mask = MV.where(MV.logical_and(lat_bound, lon_bound), 1, 0)
mask = MV.where(
MV.equal(reg3, True), 0, mask
) # Masking out the Black and Caspian Seas
mask = MV.where(MV.equal(land_mask, True), 0, mask) # 0 - Land
mask = MV.where(MV.equal(land_mask, 0), 0, mask) # 0 - Land

# NP region
if sector == "np":
lat_bound = MV.logical_and(MV.greater(lats, 45.0), MV.less_equal(lats, 65.0))
lon_bound = MV.logical_and(
MV.greater(lons_p, 90.0), MV.less_equal(lons_p, 240.0)
)
mask = MV.where(MV.logical_and(lat_bound, lon_bound), 1, 0)
mask = MV.where(MV.equal(land_mask, 0), 0, mask) # 0 - Land

# Antarctic Regions

# SA region
if sector == "sa":
lat_bound = MV.logical_and(MV.greater(lats, -90.0), MV.less_equal(lats, -55.0))
lon_bound = MV.logical_and(
MV.greater(lons_a, -60.0), MV.less_equal(lons_a, 20.0)
)
mask = MV.where(MV.logical_and(lat_bound, lon_bound), 1, 0)
mask = MV.where(MV.equal(land_mask, 0), 0, mask) # 0 - Land

# SP region
if sector == "sp":
lat_bound = MV.logical_and(MV.greater(lats, -90.0), MV.less_equal(lats, -55.0))
lon_bound = MV.logical_and(
MV.greater(lons_p, 90.0), MV.less_equal(lons_p, 300.0)
)
mask = MV.where(MV.logical_and(lat_bound, lon_bound), 1, 0)
mask = MV.where(MV.equal(land_mask, 0), 0, mask) # 0 - Land

# IO region
if sector == "io":
lat_bound = MV.logical_and(MV.greater(lats, -90.0), MV.less_equal(lats, -55.0))
lon_bound = MV.logical_and(
MV.greater(lons_p, 20.0), MV.less_equal(lons_p, 90.0)
)
mask = MV.where(MV.logical_and(lat_bound, lon_bound), 1, 0)
mask = MV.where(MV.equal(land_mask, 0), 0, mask) # 0 - Land

return mask

0 comments on commit 5c7b40c

Please sign in to comment.