From d021915b748ad71b32ea42aad1c67dcf077b4928 Mon Sep 17 00:00:00 2001 From: peterdudfield Date: Fri, 29 Nov 2024 15:03:37 +0000 Subject: [PATCH] add regridding --- .../data/mo_global/india_coords.nc | Bin 0 -> 3224 bytes india_forecast_app/data/nwp.py | 57 ++++++++++++++++++ india_forecast_app/models/pvnet/model.py | 42 +++++++++---- india_forecast_app/models/pvnet/utils.py | 31 +++++++--- tests/data/test_nwp.py | 34 +++++++++++ 5 files changed, 142 insertions(+), 22 deletions(-) create mode 100644 india_forecast_app/data/mo_global/india_coords.nc create mode 100644 india_forecast_app/data/nwp.py create mode 100644 tests/data/test_nwp.py diff --git a/india_forecast_app/data/mo_global/india_coords.nc b/india_forecast_app/data/mo_global/india_coords.nc new file mode 100644 index 0000000000000000000000000000000000000000..b97874c4aa754768fff0db989cfd7f161ebad112 GIT binary patch literal 3224 zcmb7GX>b%}5DkYR1QZBYIAZRDBaqEzvpIINZ$+Yjz|K8|$Yngh0Lr0Uf=XG62%?rC z2#9hk2wI2~DvIEVfPyz7pi)2y3Zk4|Uw_^H@t;#QH8Z<2{dK>7@AcQ~+S-Ome59%i z-KW$KpD=R5#JXG5{SkFGtsgt)wts(6&-2y!@6k-%{P&v%@@I2(rTf&OwIl26-Qo2U zDPmGmvN{{gxS;Rlxk-vV9ah)>u17KG{2%ceZ&dHAqsj66^ff6dw&VPsuiHJ;Ew*2- z2hVQq{oF^}V?W6A@!#KhY;e)J*eUt_%%so$JiECzc2@pBclQUID*cwR3-aFO32%&= ze(^v|y+m=4r2ZVye?J=VcWAi9`02r`x1bS!k1N9c-dp|4QY3R6G@;Mlo{1EWhtyDP z+NsBHM>CF#=Cs;~0k~4)w+QM3EoGgSR87O?XeH~Vr9Y{@oPji1w>71+?^m>z_1i3% zGw@J#9okABZNE&7-nslsw3B?=>u`P1Uh+zJ8&gE2OMV@mx<5JZU{7?EJUbFRy`M)X z$+vTxDMzk*sSP?y-Wir&7#WiP)s)`!OURTuGWVTXd->RCWJx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ff --git a/tests/data/test_nwp.py b/tests/data/test_nwp.py new file mode 100644 index 0000000..4c9617b --- /dev/null +++ b/tests/data/test_nwp.py @@ -0,0 +1,34 @@ +""" Tests for the nwp regridding module """ +import os +import tempfile + +import xarray as xr + +from india_forecast_app.data.nwp import regrid_nwp_data + + +def test_regrid_nwp_data(nwp_mo_global_data): + """Test the regridding of the nwp data""" + + # create a temporary dir + with tempfile.TemporaryDirectory() as temp_dir: + + # save mo data to zarr + nwp_zarr = os.environ["NWP_MO_GLOBAL_ZARR_PATH"] + + # regrid the data + nwp_zarr_save = f"{temp_dir}/nwp_regrid.zarr" + regrid_nwp_data( + nwp_zarr, "india_forecast_app/data/mo_global/india_coords.nc", nwp_zarr_save + ) + + # open the regridded data + nwp_xr = xr.open_zarr(nwp_zarr) + nwp_xr_regridded = xr.open_zarr(nwp_zarr_save) + + # check the data is different in latitude and longitude + assert not nwp_xr_regridded.latitude.equals(nwp_xr.latitude) + assert not nwp_xr_regridded.longitude.equals(nwp_xr.longitude) + + assert len(nwp_xr_regridded.latitude) == 225 + assert len(nwp_xr_regridded.longitude) == 150