Package: gridwxcomp
A package for comparing climate station time series data togridMET(or other gridded) data. Major functionality includes tools to:pair station locations with overlapping grid cellsdownload gridMET data from OpenDap servercalculate mean bias ratios between station and gridded data and other statisticsspatial interpolation of bias ratios with multiple interpolation optionsbuild geo-referenced files of point data and interpolated rastersextract zonal means for a subset of gridcellsgraphics, e.g. time series comparisons and interpolated residuals at stationsBias ratios calculated bygridwxcompcan be used to correct bias of grid to station data based on the properties of the stations. For example, monthly humidity ratios between station and grid for stations within agricultural settings can be used to estimate grid bias relative to agricultural locations.gridwxcompincludes an intuitive command line interface and a Python API.DocumentationOnline documentationInstallationCurrently we recommend using the provided conda environment file to installgridwxcompand its dependencies in a virtual environment. Download theenvironment.ymlfile and then install and activate it. If you don’t have condaget it here. To install dependencies in a virtual environment run$condaenvcreate-fenvironment.ymlTo activate the environment before usinggridwxcomprun$condaactivategridwxcompOptionally, install usingpip,$pipinstallgridwxcompDue to dependency conflicts you may have issues directly installing with pip before activating the conda environment.Alternatively, or if there are installation issues, you can manually install. First activate thegridwxcompconda environment (above). Next, clone or download the package fromGitHuborPyPIand then install locally with pip in “editable” mode. For example with cloning,$gitclonehttps://github.com/WSWUP/gridwxcomp.git$cdgridwxcompIf you are experiencing errors on installing thegridwxcompconda environment above with dependencies. For example, if the Shapely package is not installing from the enironment.yml file, remove it or modify it from the “setup.py” file in the install requirements section before you install gridwxcomp from source with:$pipinstall-e.More help with installation issues related to dependency conflicts can be found in thegridwxcompissueson GitHub, be sure to check the closed issues as well.Quick start from command lineThis example uses data provided withgridwxcompincluding climate variable time series data for four climate stations, it uses the gridMET as the gridded dataset however any uniform gridded data product can be used withgridwxcompif extra information including a vector grid file is provided.After installation you can find the location of the data needed for the example by typing the following at the command line,$python-c"import pkg_resources; print(pkg_resources.resource_filename('gridwxcomp', 'example_data/Station_Data.txt'))"Once complete, this example will calculate bias ratios between station and gridMET ETr (reference evapotranspiration), spatially interpolate GeoTIFF rasters of bias ratios at 400 meter resolution, and calculate zonal statistics of mean bias ratios for each gridMET cell in the region of the stations, similar to what is shown in the figure below.The same procedure can be done for climate variables other than ETr, e.g. observed evapotranspiration, temperature, precipitation, wind speed, short wave radiation, etc.After installing with pip thegridwxcompcommand line interface can be used from any directory, the first step pairs climate station data with their nearest gridMET cell and produces a CSV file used in the following steps,$gridwxcompprep-input<PATH_TOexample_data/Station_Data.txt>This will result in the file “merged_input.csv”. Next download matching gridMET climate time series withOpeNDAPby running$gridwxcompdownload-gridmet-opendapmerged_input.csv-y2016-2017The time series of gridMET data that correpond with the stations in “merged_input.csv” will be saved to a new folder called “gridmet_data” by default. In this case only the years 2016-2017 are used.Next, to calculate mean monthly and annual bias ratios for each station/gridMET pair along with other statistics and metadata and save to CSV files,$gridwxcompcalc-bias-ratiosmerged_input.csv-omonthly_ratiosLast, to calculate interpolated surfaces of mean bias ratios and extract zonal means to gridMET cells using the default interpolation method (inverse distance weighting):$gridwxcompspatialmonthly_ratios/etr_mm_summary_comp_all_yrs.csv-b5The[-b5]option indicates that we want to expand the rectangular bounding area for interpolation by five gridMET cells (extrapolation in the outer regions).GeoTIFF rasters of interpolated ratios will be saved to “monthly_ratios/spatial/etr_mm_invdist_400m/”. Note, the gridMET variable name (etr_mm), the interpolation method (invdist), and the raster resolution (400m) are specified in the output directory. A fishnet grid with gridMET id values and a point shapefile of station ratios should all be created and saved in the “monthly_ratios/spatial/” directory.The output file “monthly_ratios/spatial/etr_mm_invdist_400m/gridMET_stats.csv” contains monthly bias ratios for each gridMET cell in the interpolation region, similar to what is shown below.GRIDMET_IDJan_meanFeb_meanMar_mean…5159020.660.760.96…5145160.660.770.96…5131300.670.770.97…5117440.670.780.97…5103580.680.790.97………………NoteGRIDMET_IDis the index of the master gridMET dataset 4 km fishnet grid starting at 0 in the upper left corner and moving across rows and down columns. This value can be joined with previously created data, e.g. the ID values can be joined to centroid coordinates of gridMET cells.Bar plots that show the residual between station mean ratios and interpolated estimates are saved to “monthly_ratios/spatial/etr_mm_invdist_400m/residual_plots/”.To get abbreviated descriptions for any of the abovegridwxcompcommands use the[--help]option, e.g.$gridwxcompspatial--help