Skip to content

Commit 19eb8b7

Browse files
Merge pull request #15 from CMCC-Foundation/plot_update
Updates on download script and plot label sizes
2 parents bd829b5 + ef87668 commit 19eb8b7

File tree

2 files changed

+21
-15
lines changed

2 files changed

+21
-15
lines changed

src/download/download_copernicus_parser.py

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,11 @@ def download_copernicus(
9090
dataset_id_curr = "med-cmcc-cur-rean-h"
9191
dataset_id_temp = "med-cmcc-tem-rean-d"
9292
output_name = output_name.format("reanalysis")
93-
9493
files = []
94+
95+
# Normalized date to be sure to get enough time slices of dataset
96+
start_time = start_time.normalize()
97+
9598
for dataset in [dataset_id_curr, dataset_id_temp]:
9699

97100
if "cur" in dataset:
@@ -111,10 +114,10 @@ def download_copernicus(
111114
)
112115
# Add depth dimension (0 m) to 2D dataset
113116
ds = xr.open_dataset(f"{output_path}curr.nc")
114-
ds = ds.expand_dims(depth=[0])
117+
ds = ds.expand_dims(depth=[0, 10, 30, 120])
115118
ds.to_netcdf(f"{output_path}curr.nc")
116-
117119
files.append(output_path + "curr.nc")
120+
118121
else:
119122
copernicusmarine.subset(
120123
dataset_id=dataset_id_temp,
@@ -132,7 +135,12 @@ def download_copernicus(
132135
username=user,
133136
password=password,
134137
)
135-
138+
ds_temp = xr.open_dataset(f"{output_path}temp.nc")
139+
ds_temp = ds_temp.sel(depth=[0, 10, 30, 120], method="nearest")
140+
ds_temp["depth"] = [0, 10, 30, 120]
141+
ds_temp = ds_temp.resample(time='1H').ffill()
142+
ds_temp = ds_temp.load() # Load the dataset into memory to release the file handle
143+
ds_temp.to_netcdf(f"{output_path}temp.nc")
136144
files.append(output_path + "temp.nc")
137145

138146
# Transform to medslik standards
@@ -141,12 +149,6 @@ def download_copernicus(
141149
# Rename variables only if they exist in the dataset
142150
ds = Utils.rename_netcdf_variables_mdk3(ds)
143151

144-
# Selecting only 4 layers
145-
ds = ds.sel(depth=[0, 10, 30, 120], method="nearest")
146-
147-
# Modifying labels to simplfy drop in temperature columns
148-
ds["depth"] = [0, 10, 30, 120]
149-
150152
# Selecting only the relavent variables
151153
ds = ds[["uo", "vo", "thetao"]]
152154

@@ -164,7 +166,8 @@ def download_copernicus(
164166
dataset_id_curr = "cmems_mod_med_phy-cur_anfc_4.2km-2D_PT1H-m"
165167
dataset_id_temp = "cmems_mod_med_phy-tem_anfc_4.2km-2D_PT1H-m"
166168
output_name = output_name.format("analysis")
167-
169+
# Normalized date to be sure to get enough time slices of dataset
170+
start_time = start_time.normalize()
168171
files = []
169172
for dataset in [dataset_id_curr, dataset_id_temp]:
170173

@@ -228,7 +231,8 @@ def download_copernicus(
228231
dataset_id_curr = "cmems_mod_med_phy-cur_anfc_4.2km-3D_PT1H-m"
229232
dataset_id_temp = "cmems_mod_med_phy-tem_anfc_4.2km-3D_PT1H-m"
230233
output_name = output_name.format("analysis")
231-
234+
# Normalized date to be sure to get enough time slices of dataset
235+
start_time = start_time.normalize()
232236
files = []
233237
for dataset in [dataset_id_curr, dataset_id_temp]:
234238

src/plot/plot_mdk3.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -224,8 +224,10 @@ def plot_matplotlib(self,lon_min,lon_max,lat_min,lat_max):
224224
ax1.set_title(
225225
f"Surface Oil Concentration\n{current_time}", fontsize=18, pad=20
226226
)
227-
ax1.set_xlabel(lon_label, fontsize=12)
228-
ax1.set_ylabel(lat_label, fontsize=12)
227+
ax1.set_xlabel(lon_label, fontsize=14)
228+
ax1.set_ylabel(lat_label, fontsize=14)
229+
ax1.tick_params(axis='both', which='major', labelsize=12)
230+
ax1.tick_params(axis='both', which='minor', labelsize=12)
229231
ax1.set_xlim(lon_min, lon_max)
230232
ax1.set_ylim(lat_min, lat_max)
231233
plt.grid()
@@ -239,7 +241,7 @@ def plot_matplotlib(self,lon_min,lon_max,lat_min,lat_max):
239241
cbar = plt.colorbar(
240242
c, cax=cbar_ax, orientation="horizontal", ticks=extended_levels[:-1]
241243
)
242-
cbar.set_label(r"tons km$^{-2}$", fontsize=14)
244+
cbar.set_label(r"tons km$^{-2}$", fontsize=13)
243245

244246
# Format the colorbar ticks
245247
cbar.ax.xaxis.set_major_formatter(FormatStrFormatter(format_string))

0 commit comments

Comments
 (0)