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
43fa9be1
Commit
43fa9be1
authored
4 years ago
by
Beatriz Recinos
Browse files
Options
Download
Email Patches
Plain Diff
changes to animation buoy plot tools
parent
974a6783
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
63 additions
and
52 deletions
+63
-52
scripts/plot_cci_buoy_error.py
scripts/plot_cci_buoy_error.py
+15
-12
sst_tools/workflow_sst.py
sst_tools/workflow_sst.py
+48
-40
No files found.
scripts/plot_cci_buoy_error.py
View file @
43fa9be1
...
...
@@ -127,18 +127,21 @@ for hour in hours_list_to_plot:
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
=
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
())
if
buoy_data
.
empty
:
pass
else
:
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
())
# Now adding the colour-bar
cax
,
kw
=
colorbar
.
make_axes
(
ax
,
location
=
'top'
,
pad
=
0.07
,
aspect
=
30
)
...
...
This diff is collapsed.
Click to expand it.
sst_tools/workflow_sst.py
View file @
43fa9be1
...
...
@@ -89,46 +89,54 @@ 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
)]
# 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
),
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
day_df
=
day_df
.
dropna
(
subset
=
[
'lon'
,
'lat'
])
if
day_df
.
empty
:
day_df
=
day_df
.
assign
(
cci_sst
=
np
.
NaN
)
day_df
[
'cci_sst_2x2'
]
=
np
.
NaN
day_df
[
'cci_sst_1x1'
]
=
np
.
NaN
day_df
=
day_df
.
assign
(
sst_z_mean
=
np
.
NaN
)
day_df
[
'age'
]
=
day_df
[
'date'
].
apply
(
lambda
x
:
age
.
get
(
x
.
strftime
(
'%Y-%m-%d'
)))
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
),
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
...
...
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