Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
brivas
ORCHESTRA-SST
Commits
eebc7c7b
Commit
eebc7c7b
authored
4 years ago
by
Beatriz Recinos
Browse files
Options
Download
Email Patches
Plain Diff
fixing broken animation script
parent
40a734f3
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
82 additions
and
83 deletions
+82
-83
scripts/plot_cci_buoy_error.py
scripts/plot_cci_buoy_error.py
+38
-40
sst_tools/workflow_sst.py
sst_tools/workflow_sst.py
+44
-43
No files found.
scripts/plot_cci_buoy_error.py
View file @
eebc7c7b
...
...
@@ -38,7 +38,7 @@ month = int(sys.argv[4])
day_to_plot
=
int
(
sys
.
argv
[
5
])
# From SLURM ARRAY
lat_bnds
=
[
-
90
,
-
25
]
lon_bnds
=
[
-
1
5
0
,
1
5
0
]
lon_bnds
=
[
-
1
2
0
,
1
2
0
]
extent
=
np
.
append
(
lon_bnds
,
lat_bnds
)
print
(
extent
)
...
...
@@ -125,43 +125,41 @@ for hour in hours_list_to_plot:
cci_to_plot
=
daily_sst_zonal_mean
.
isel
(
time
=
len
(
sst
.
time
)
-
1
)
plot_sst
.
plot_sst_map
(
cci_to_plot
,
ax
=
ax
,
vmin
=-
7
,
vmax
=
7
)
if
df_buoy
is
None
:
plt
.
close
(
f
)
pass
else
:
for
date
in
dates_list
:
try
:
buoy_data
=
df_buoy
[
date
.
strftime
(
'%Y-%m-%d'
)][
0
]
xx
=
buoy_data
.
lon
.
values
yy
=
buoy_data
.
lat
.
values
s
=
30
/
buoy_data
.
age
.
values
temp_diff
=
buoy_data
[
'cci_sst'
]
-
buoy_data
[
'cci_sst_1x1'
]
temp
=
temp_diff
.
values
cmap
=
plt
.
get_cmap
(
'PiYG_r'
,
20
)
img
=
ax
.
scatter
(
xx
,
yy
,
s
=
s
,
c
=
temp
,
cmap
=
cmap
,
vmin
=-
1
,
vmax
=
1
,
edgecolors
=
'k'
,
linewidths
=
0.5
,
transform
=
crs
.
PlateCarree
())
except
IndexError
:
pass
# Now adding the colour-bar
cax
,
kw
=
colorbar
.
make_axes
(
ax
,
location
=
'top'
,
pad
=
0.07
,
aspect
=
30
)
out
=
f
.
colorbar
(
img
,
cax
=
cax
,
**
kw
)
out
.
set_label
(
'Temperature difference ($^{\circ}$C)
\n
'
'CCI-SST at buoy coords - CCI-SST mean in a 1x1 gridbox centred at '
'buoy coords'
,
size
=
'small'
,
# \n ''cci-sst at buoy coords - cci-sst avg in a 2x2 gridbox \n '
weight
=
'bold'
)
f
.
suptitle
(
plot_end_date
)
#ax.set_title()
plot_name
=
str
(
int
(
year
))
+
'_'
+
f
"
{
str
(
int
(
month
)):
0
>
2
}
"
+
f
"
{
str
(
int
(
day_to_plot
)):
0
>
2
}
"
+
f
"
{
str
(
int
(
hour
)):
0
>
2
}
"
plt
.
savefig
(
os
.
path
.
join
(
config
[
'plots_path'
],
plot_name
+
'.png'
),
# if df_buoy is None:
# plt.close(f)
# pass
# else:
for
date
in
dates_list
:
buoy_data
=
df_buoy
[
date
.
strftime
(
'%Y-%m-%d'
)][
0
]
xx
=
buoy_data
.
lon
.
values
yy
=
buoy_data
.
lat
.
values
s
=
20
/
buoy_data
.
age
.
values
temp_diff
=
buoy_data
[
'cci_sst'
]
-
buoy_data
[
'cci_sst_1x1'
]
temp
=
temp_diff
.
values
cmap
=
plt
.
get_cmap
(
'PiYG_r'
,
20
)
img
=
ax
.
scatter
(
xx
,
yy
,
s
=
s
,
c
=
temp
,
cmap
=
cmap
,
vmin
=-
1
,
vmax
=
1
,
edgecolors
=
'k'
,
linewidths
=
0.5
,
transform
=
crs
.
PlateCarree
())
# except IndexError:
# pass
# Now adding the colour-bar
cax
,
kw
=
colorbar
.
make_axes
(
ax
,
location
=
'top'
,
pad
=
0.07
,
aspect
=
30
)
out
=
f
.
colorbar
(
img
,
cax
=
cax
,
**
kw
)
out
.
set_label
(
'Temperature difference ($^{\circ}$C)
\n
'
'CCI-SST at buoy coords - CCI-SST mean in a 1x1 gridbox centred at '
'buoy coords'
,
size
=
'small'
,
# \n ''cci-sst at buoy coords - cci-sst avg in a 2x2 gridbox \n '
weight
=
'bold'
)
f
.
suptitle
(
plot_end_date
)
#ax.set_title()
plot_name
=
str
(
int
(
year
))
+
'_'
+
f
"
{
str
(
int
(
month
)):
0
>
2
}
"
+
f
"
{
str
(
int
(
day_to_plot
)):
0
>
2
}
"
+
f
"
{
str
(
int
(
hour
)):
0
>
2
}
"
plt
.
savefig
(
os
.
path
.
join
(
config
[
'plots_path'
],
plot_name
+
'.png'
),
bbox_inches
=
'tight'
,
pad_inches
=
0.25
)
plt
.
clf
()
plt
.
close
(
f
)
\ No newline at end of file
plt
.
clf
()
plt
.
close
(
f
)
\ No newline at end of file
This diff is collapsed.
Click to expand it.
sst_tools/workflow_sst.py
View file @
eebc7c7b
import
logging
import
pandas
as
pd
import
numpy
as
np
np
.
seterr
(
divide
=
'ignore'
,
invalid
=
'ignore'
)
import
xarray
as
xr
from
scipy.stats
import
binned_statistic_2d
from
datetime
import
datetime
...
...
@@ -89,52 +90,52 @@ def process_hour_drift_from_start_to_end(df,
lat_n
=
extent
[
3
]
day_df
=
day_df
[
day_df
[
'lon'
].
between
(
lon_w
,
lon_e
)
&
day_df
[
'lat'
].
between
(
lat_s
,
lat_n
)]
day_df
=
day_df
.
dropna
(
subset
=
[
'lon'
,
'lat'
])
if
day_df
.
empty
:
pass
else
:
# It is important when using interp that you convert to xarray!
yy
=
xr
.
DataArray
(
day_df
.
lat
.
values
,
dims
=
'z'
)
xx
=
xr
.
DataArray
(
day_df
.
lon
.
values
,
dims
=
'z'
)
# Select time chunk from cci sst dask-xarray
time_chunk
=
cci_data
.
loc
[
dict
(
time
=
date
.
strftime
(
'%Y-%m-%d'
))]
time_chunk
=
xr
.
concat
(
time_chunk
.
load
(),
dim
=
'time'
)
# Interpolate sst from time chunk to buoy coord and save it
cci_sst_in_buoy_cord
=
time_chunk
.
interp
(
lat
=
yy
,
lon
=
xx
)
cci_sst_in_buoy_cord
=
cci_sst_in_buoy_cord
.
to_dataframe
().
analysed_sst
.
values
day_df
=
day_df
.
assign
(
cci_sst
=
cci_sst_in_buoy_cord
)
# Calculate gridded averages
temp_2x2d
=
[]
temp_1x1d
=
[]
for
x
,
y
in
zip
(
xx
,
yy
):
chunk_2x2d
=
time_chunk
.
sel
(
lat
=
slice
(
y
-
2
,
y
+
2
),
#
day_df = day_df.dropna(subset=['lon', 'lat'])
#
if day_df.empty:
#
pass
#
else:
# It is important when using interp that you convert to xarray!
yy
=
xr
.
DataArray
(
day_df
.
lat
.
values
,
dims
=
'z'
)
xx
=
xr
.
DataArray
(
day_df
.
lon
.
values
,
dims
=
'z'
)
# Select time chunk from cci sst dask-xarray
time_chunk
=
cci_data
.
loc
[
dict
(
time
=
date
.
strftime
(
'%Y-%m-%d'
))]
time_chunk
=
xr
.
concat
(
time_chunk
.
load
(),
dim
=
'time'
)
# Interpolate sst from time chunk to buoy coord and save it
cci_sst_in_buoy_cord
=
time_chunk
.
interp
(
lat
=
yy
,
lon
=
xx
)
cci_sst_in_buoy_cord
=
cci_sst_in_buoy_cord
.
to_dataframe
().
analysed_sst
.
values
day_df
=
day_df
.
assign
(
cci_sst
=
cci_sst_in_buoy_cord
)
# Calculate gridded averages
temp_2x2d
=
[]
temp_1x1d
=
[]
for
x
,
y
in
zip
(
xx
,
yy
):
chunk_2x2d
=
time_chunk
.
sel
(
lat
=
slice
(
y
-
2
,
y
+
2
),
lon
=
slice
(
x
-
2
,
x
+
2
))
chunk_1x1d
=
time_chunk
.
sel
(
lat
=
slice
(
y
-
1
,
y
+
1
),
chunk_1x1d
=
time_chunk
.
sel
(
lat
=
slice
(
y
-
1
,
y
+
1
),
lon
=
slice
(
x
-
1
,
x
+
1
))
temp_2x2d
.
append
(
np
.
float32
(
chunk_2x2d
.
mean
().
values
))
temp_1x1d
.
append
(
np
.
float32
(
chunk_1x1d
.
mean
().
values
))
# Save it
day_df
[
'cci_sst_2x2'
]
=
temp_2x2d
day_df
[
'cci_sst_1x1'
]
=
temp_1x1d
# Interpolate zonal mean from cci data to the buoy coord and save it
time_chunk_z_m
=
cci_zonal_mean
.
loc
[
dict
(
time
=
date
.
strftime
(
'%Y-%m-%d'
))]
time_chunk_z_m
=
xr
.
concat
(
time_chunk_z_m
.
load
(),
dim
=
'time'
)
z_mean
=
time_chunk_z_m
.
interp
(
lat
=
yy
)
z_mean
=
z_mean
.
to_dataframe
().
analysed_sst
.
values
day_df
=
day_df
.
assign
(
sst_z_mean
=
lambda
x
:
x
.
sst
-
z_mean
)
# Give each date an age
day_df
[
'age'
]
=
day_df
[
'date'
].
apply
(
lambda
x
:
age
.
get
(
x
.
strftime
(
'%Y-%m-%d'
)))
# Save all in a dictionary lead by date
d
[
date
.
strftime
(
'%Y-%m-%d'
)].
append
(
day_df
)
return
d
temp_2x2d
.
append
(
np
.
float32
(
chunk_2x2d
.
mean
().
values
))
temp_1x1d
.
append
(
np
.
float32
(
chunk_1x1d
.
mean
().
values
))
# Save it
day_df
[
'cci_sst_2x2'
]
=
temp_2x2d
day_df
[
'cci_sst_1x1'
]
=
temp_1x1d
# Interpolate zonal mean from cci data to the buoy coord and save it
time_chunk_z_m
=
cci_zonal_mean
.
loc
[
dict
(
time
=
date
.
strftime
(
'%Y-%m-%d'
))]
time_chunk_z_m
=
xr
.
concat
(
time_chunk_z_m
.
load
(),
dim
=
'time'
)
z_mean
=
time_chunk_z_m
.
interp
(
lat
=
yy
)
z_mean
=
z_mean
.
to_dataframe
().
analysed_sst
.
values
day_df
=
day_df
.
assign
(
sst_z_mean
=
lambda
x
:
x
.
sst
-
z_mean
)
# Give each date an age
day_df
[
'age'
]
=
day_df
[
'date'
].
apply
(
lambda
x
:
age
.
get
(
x
.
strftime
(
'%Y-%m-%d'
)))
# Save all in a dictionary lead by date
d
[
date
.
strftime
(
'%Y-%m-%d'
)].
append
(
day_df
)
return
d
def
compute_coarsen
(
data
,
resolution
):
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment