Skip to content

Commit

Permalink
started implementing goes download script
Browse files Browse the repository at this point in the history
  • Loading branch information
Lilli Freischem committed Dec 4, 2023
1 parent 3b35214 commit b6b32b6
Show file tree
Hide file tree
Showing 5 changed files with 1,088 additions and 42 deletions.
8 changes: 4 additions & 4 deletions notebooks/0.1.1-GOES2GO.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@
},
{
"cell_type": "code",
"execution_count": 33,
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -124,20 +124,20 @@
},
{
"cell_type": "code",
"execution_count": 34,
"execution_count": 3,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"📦 Finished downloading [15] files to [data/noaa-goes16/ABI-L1b-RadF].\n"
"📦 Finished downloading [16] files to [/Users/lillifreischem/data/noaa-goes16/ABI-L1b-RadF].\n"
]
}
],
"source": [
"# download the data nearest a specific time\n",
"files = G.nearesttime('2018-10-01 17:00', return_as='filelist', save_dir='./data/')"
"files = G.nearesttime('2018-10-02 17:00', return_as='filelist')#, save_dir=None)"
]
},
{
Expand Down
205 changes: 205 additions & 0 deletions notebooks/0.3-GOES-downsampling.ipynb
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
}
24 changes: 24 additions & 0 deletions notebooks/goes-scripts/goes_downsample.py
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
...
Loading

0 comments on commit b6b32b6

Please sign in to comment.