@@ -927,14 +927,17 @@ def elevation_stochastic_downselect(
927
927
928
928
929
929
def interpolate_analysis (
930
- result : xr .Dataset , data_var : str , method = "nearest"
930
+ result : xr .Dataset , data_var : str , method = "nearest" , resolution = 100j ,
931
931
) -> Tuple [np .ndarray , np .ndarray , np .ndarray ]:
932
932
"""
933
933
Interpolate sparse spatial result data against DataArray coordinates.
934
934
Takes DataArray instead of Dataset, index one variable of a dataset to get a dataarray.
935
935
936
936
Parameters:
937
937
-----------
938
+ resolution: complex
939
+ Change the amount the input is interpolated.
940
+ For more interpolation set higher (200j is more than 100j)
938
941
939
942
Result:
940
943
-------
@@ -951,21 +954,51 @@ def interpolate_analysis(
951
954
) # probably a nicer way to do this
952
955
953
956
grid_lat , grid_lon = np .mgrid [
954
- df ["latitude" ].min () : df ["latitude" ].max () : 100j ,
955
- df ["longitude" ].min () : df ["longitude" ].max () : 100j ,
957
+ df ["latitude" ].min () : df ["latitude" ].max () : resolution ,
958
+ df ["longitude" ].min () : df ["longitude" ].max () : resolution ,
956
959
]
957
960
958
961
grid_z = griddata (data [:, 0 :2 ], data [:, 2 ], xi = (grid_lat , grid_lon ), method = method )
959
962
960
963
return grid_z , grid_lat , grid_lon
961
964
962
965
963
- def plot_sparse_analysis (result : xr .Dataset , data_var : str , method = "nearest" ) -> None :
966
+ # api could be updated to match that of plot_USA
967
+ def plot_sparse_analysis (
968
+ result : xr .Dataset ,
969
+ data_var : str ,
970
+ method = "nearest" ,
971
+ resolution :complex = 100j ,
972
+ figsize :tuple = (10 ,8 ),
973
+ ) -> None :
974
+ """
975
+ Plot the output of a sparse geospatial analysis using interpolation.
976
+
977
+ Parameters
978
+ -----------
979
+ result: xr.Dataset
980
+ xarray dataset in memory containing coordinates['longitude', 'latitude'] and at least one datavariable.
981
+ data_var: str
982
+ name of datavariable to plot from result
983
+ method: str
984
+ interpolation method.
985
+ Options: `'nearest', 'linear', 'cubic'`
986
+ See [`scipy.interpolate.griddata`](https://docs.scipy.org/doc/scipy/reference/generated/scipy.interpolate.griddata.html)
987
+ resolution: complex
988
+ Change the amount the input is interpolated.
989
+ For more interpolation set higher (200j is more than 100j)
990
+
991
+ Returns
992
+ -------
993
+ fig, ax: tuple
994
+ matplotlib figure and axes of plot
995
+ """
996
+
964
997
grid_values , lat , lon = interpolate_analysis (
965
- result = result , data_var = data_var , method = method
998
+ result = result , data_var = data_var , method = method , resolution = resolution
966
999
)
967
1000
968
- fig = plt .figure ()
1001
+ fig = plt .figure (figsize = figsize )
969
1002
ax = fig .add_axes ([0 , 0 , 1 , 1 ], projection = ccrs .LambertConformal (), frameon = False )
970
1003
ax .patch .set_visible (False )
971
1004
@@ -977,7 +1010,7 @@ def plot_sparse_analysis(result: xr.Dataset, data_var: str, method="nearest") ->
977
1010
origin = "lower" ,
978
1011
cmap = "viridis" ,
979
1012
transform = ccrs .PlateCarree (),
980
- ) # should this be trnsposed
1013
+ )
981
1014
982
1015
shapename = "admin_1_states_provinces_lakes"
983
1016
states_shp = shpreader .natural_earth (
@@ -994,7 +1027,9 @@ def plot_sparse_analysis(result: xr.Dataset, data_var: str, method="nearest") ->
994
1027
cbar = plt .colorbar (img , ax = ax , orientation = "vertical" , fraction = 0.02 , pad = 0.04 )
995
1028
cbar .set_label ("Value" )
996
1029
997
- plt .title ("Interpolated Heatmap " )
1030
+ plt .title (f "Interpolated Sparse Analysis, { data_var } " )
998
1031
plt .xlabel ("Longitude" )
999
1032
plt .ylabel ("Latitude" )
1000
1033
plt .show ()
1034
+
1035
+ return fig , ax
0 commit comments