-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
started implementing goes download script
- Loading branch information
Lilli Freischem
committed
Dec 4, 2023
1 parent
3b35214
commit b6b32b6
Showing
5 changed files
with
1,088 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,205 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 1, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"from scipy.interpolate import LinearNDInterpolator, NearestNDInterpolator\n", | ||
"import numpy as np\n", | ||
"# from xy_to_latlon import calc_latlon\n", | ||
"\n", | ||
"def downsample(ds, target_points):\n", | ||
" \"\"\"\n", | ||
" target_points\n", | ||
" \"\"\"\n", | ||
" # attach latitude & longitude coordinates to xr.Datasets\n", | ||
" ds = calc_latlon(ds)\n", | ||
" \n", | ||
" # extract 1d arrays of latitudes and longitudes\n", | ||
" lat = ds.lat.to_numpy().flatten()\n", | ||
" lon = ds.lon.to_numpy().flatten()\n", | ||
" \n", | ||
" # turn into 2d array of latitudes and longitudes\n", | ||
" points = np.vstack((lon, lat)).T\n", | ||
" \n", | ||
" # initialise interpolation\n", | ||
" nn_interpolation = NearestNDInterpolator(points, ds.Rad)\n", | ||
" interpolated_nn = nn_interpolation(target_points)\n", | ||
" \n", | ||
" # create new xr.Dataset with lowres data \n", | ||
" ..." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 2, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import xarray as xr" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 3, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"ds = xr.load_dataset('../data/noaa-goes16/ABI-L1b-RadF/2018/274/17/OR_ABI-L1b-RadF-M3C01_G16_s20182741700337_e20182741711104_c20182741711147.nc')\n", | ||
"ds_target = xr.load_dataset('../data/noaa-goes16/ABI-L1b-RadF/2018/274/17/OR_ABI-L1b-RadF-M3C04_G16_s20182741700337_e20182741711104_c20182741711130.nc')" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 4, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"data": { | ||
"text/plain": [ | ||
"(10848,)" | ||
] | ||
}, | ||
"execution_count": 4, | ||
"metadata": {}, | ||
"output_type": "execute_result" | ||
} | ||
], | ||
"source": [ | ||
"ds.x.to_numpy().shape" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 5, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"x = ds.x.to_numpy()\n", | ||
"y = ds.y.to_numpy()\n", | ||
"\n", | ||
"x_target = ds_target.x.to_numpy()\n", | ||
"y_target = ds_target.y.to_numpy()" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 6, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# points = np.vstack((x, y)).T\n", | ||
"# points_target = np.vstack((x_target, y_target)).T" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 7, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"xx, yy = np.meshgrid(x, y)\n", | ||
"points = np.vstack((xx.flatten(), yy.flatten())).T" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 8, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"nn_interpolation = NearestNDInterpolator(points, ds.Rad.to_numpy().flatten())" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 18, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"data": { | ||
"text/plain": [ | ||
"(117679104,)" | ||
] | ||
}, | ||
"execution_count": 18, | ||
"metadata": {}, | ||
"output_type": "execute_result" | ||
} | ||
], | ||
"source": [ | ||
"ds.Rad.to_numpy().flatten().shape" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 20, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"data": { | ||
"text/plain": [ | ||
"(10848, 10848)" | ||
] | ||
}, | ||
"execution_count": 20, | ||
"metadata": {}, | ||
"output_type": "execute_result" | ||
} | ||
], | ||
"source": [ | ||
"xx.shape" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 21, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"data": { | ||
"text/plain": [ | ||
"(10848, 10848)" | ||
] | ||
}, | ||
"execution_count": 21, | ||
"metadata": {}, | ||
"output_type": "execute_result" | ||
} | ||
], | ||
"source": [ | ||
"ds.Rad.shape" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "gcmodel", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.10.6" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 2 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
from scipy.interpolate import LinearNDInterpolator, NearestNDInterpolator | ||
import numpy as np | ||
from xy_to_latlon import calc_latlon | ||
|
||
def downsample(ds, target_points): | ||
""" | ||
target_points | ||
""" | ||
# attach latitude & longitude coordinates to xr.Datasets | ||
ds = calc_latlon(ds) | ||
|
||
# extract 1d arrays of latitudes and longitudes | ||
lat = ds.lat.to_numpy().flatten() | ||
lon = ds.lon.to_numpy().flatten() | ||
|
||
# turn into 2d array of latitudes and longitudes | ||
points = np.vstack((lon, lat)).T | ||
|
||
# initialise interpolation | ||
nn_interpolation = NearestNDInterpolator(points, ds.Rad) | ||
interpolated_nn = nn_interpolation(target_points) | ||
|
||
# create new xr.Dataset with lowres data | ||
... |
Oops, something went wrong.