Skip to content

Commit 5862657

Browse files
authored
Merge pull request #662 from yixinmao/fix_run_cell_mask_image_driver
Fix run_cell bug in image driver
2 parents 13b8cc8 + d0c7229 commit 5862657

File tree

8 files changed

+170
-99
lines changed

8 files changed

+170
-99
lines changed

docs/Development/ReleaseNotes.md

+5
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@ To check which release of VIC you are running:
4545
7. Fixed a bug related to `dz_node` and `node_depth` variables in image driver output state file ([GH#657](https://github.com/UW-Hydro/VIC/pull/657))
4646

4747
Before the fix, `dz_node` and `node_depth` in image driver output state file were not spatially distributed, which was wrong. Now these two variables are spatially distributed in the output state file.
48+
49+
6. Fixed a bug related to `run_cell` and `mask` variables in image driver inputs ([GH#662]((https://github.com/UW-Hydro/VIC/pull/662)))
50+
51+
Before the fix, active cell was controlled by `mask` variable in the domain file in image driver, and `run_cell` variable in the parameter file was not actually used. Now `run_cell` variable in the parameter file controls active cells (`run_cell` must be within the mask defined by the domain file).
52+
4853

4954
------------------------------
5055

docs/Documentation/Drivers/Image/Domain.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Below is a list of variables in the domain netCDF file. The dimensions of the ne
88
|------------|-------------|----------|--------|-------------|
99
| LAT | [lat] | degree | double | Latitudes |
1010
| LON | [lon] | degree | double | Longitues |
11-
| MASK | [lat, lon] | N/A | integer | Mask of VIC run. 1 for active cells for VIC run; 0 indicates inactive grid cells. VIC will not run at grid cells with MASK = 0 or missing value. |
11+
| MASK | [lat, lon] | N/A | integer | Mask of domain. 1 for grid cells inside considered domain; 0 for grid cells outside of domain. Cells outside of domain will not be run. Use run_cell variable in the parameter file to turn on/off active cells inside domain. |
1212
| AREA | [lat, lon] | m2 | double | Area of grid cells. |
1313
| FRAC | [lat, lon] | N/A | double | Fraction of grid cells that is land. |
1414

@@ -22,7 +22,7 @@ dimensions:
2222
lon = 125 ;
2323
variables:
2424
int mask(lat, lon) ;
25-
mask:comment = "0 indicates grid cell is not active" ;
25+
mask:comment = "0 indicates grid cell outside of domain" ;
2626
mask:long_name = "domain mask" ;
2727
double lon(lon) ;
2828
lon:long_name = "longitude coordinate" ;

docs/Documentation/Drivers/Image/ForcingData.md

-5
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,6 @@ variables:
3838
lat:long_name = "latitude of grid cell center" ;
3939
lat:units = "degrees_north" ;
4040
lat:axis = "Y" ;
41-
double mask(lat, lon) ;
42-
mask:_FillValue = 0. ;
43-
mask:comment = "0 value indicates cell is not active" ;
44-
mask:long_name = "fraction of grid cell that is activedomain mask" ;
45-
mask:note = "unitlessunitless" ;
4641
float prcp(time, lat, lon) ;
4742
prcp:_FillValue = 9.96921e+36f ;
4843
prcp:long_name = "PREC" ;

docs/Documentation/Drivers/Image/Params.md

+1-8
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Below is a list of soil parameters.
1616

1717
| Variable Name | Dimension | Units | Type | Number of Values | Description |
1818
|--------------------------|--------------------|----------|--------|------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
19-
| run_cell | [lat, lon] | N/A | int | 1 | 1 = Run Grid Cell, 0 = Do Not Run |
19+
| run_cell | [lat, lon] | N/A | int | 1 | 1 = Run Grid Cell, 0 = Do Not Run. Must be zero for all grid cells outside of the mask defined in the domain netCDF file. |
2020
| gridcel | [lat, lon] | N/A | int | 1 | Grid cell number |
2121
| lat | [lat, lon] | degrees | double | 1 | Latitude of grid cell |
2222
| lon | [lat, lon] | degrees | double | 1 | Longitude of grid cell |
@@ -173,13 +173,6 @@ variables:
173173
double lon(lon) ;
174174
lon:units = "degrees_east" ;
175175
lon:long_name = "longitude of grid cell center" ;
176-
int mask(lat, lon) ;
177-
mask:long_name = "area of grid cell" ;
178-
mask:comment = "0 value indicates cell is not active" ;
179-
mask:note = "unitless" ;
180-
mask:standard_name = "area" ;
181-
mask:units = "m2" ;
182-
mask:axis = "Y" ;
183176
int layer(nlayer) ;
184177
layer:long_name = "soil layer" ;
185178
int run_cell(lat, lon) ;

vic/drivers/shared_image/include/vic_driver_shared_image.h

+4-2
Original file line numberDiff line numberDiff line change
@@ -196,8 +196,10 @@ void compare_ncdomain_with_global_domain(char *ncfile);
196196
void free_force(force_data_struct *force);
197197
void free_veg_hist(veg_hist_struct *veg_hist);
198198
void get_domain_type(char *cmdstr);
199-
size_t get_global_domain(char *fname, domain_struct *global_domain,
200-
bool coords_only);
199+
size_t get_global_domain(char *domain_nc_name, char *param_nc_name,
200+
domain_struct *global_domain);
201+
void copy_domain_info(domain_struct *domain_from, domain_struct *domain_to);
202+
void get_nc_latlon(char *nc_name, domain_struct *nc_domain);
201203
size_t get_nc_dimension(char *nc_name, char *dim_name);
202204
void get_nc_var_attr(char *nc_name, char *var_name, char *attr_name,
203205
char **attr);

vic/drivers/shared_image/src/check_domain_info.c

+10-11
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@
2828
#include <vic_driver_shared_image.h>
2929

3030
/******************************************************************************
31-
* @brief Check that the cooridnates, dimensions, and mask variables in a
32-
netcdf file matches the global domain.
31+
* @brief Check that the cooridnates and dimensions in a netcdf file matches
32+
the global domain.
3333
*****************************************************************************/
3434
void
3535
compare_ncdomain_with_global_domain(char *ncfile)
@@ -40,10 +40,14 @@ compare_ncdomain_with_global_domain(char *ncfile)
4040

4141
size_t i;
4242

43-
ncfile_domain.info = global_domain.info;
44-
45-
// read the domain info from ncfile (e.g. parameters file or state file)
46-
get_global_domain(ncfile, &ncfile_domain, true);
43+
// read the lat lon coordinates info from ncfile
44+
// (e.g. parameters file or state file)
45+
ncfile_domain.locations =
46+
malloc(global_domain.ncells_total *
47+
sizeof(*(ncfile_domain.locations)));
48+
check_alloc_status(ncfile_domain.locations, "Memory allocation error.");
49+
copy_domain_info(&global_domain, &ncfile_domain);
50+
get_nc_latlon(ncfile, &ncfile_domain);
4751

4852
// using the ncfile_domain, we can compare the values to the global domain.
4953

@@ -57,11 +61,6 @@ compare_ncdomain_with_global_domain(char *ncfile)
5761

5862
// loop over all grid cells and check that the two domains are identical
5963
for (i = 0; i < global_domain.ncells_total; i++) {
60-
// mask matches
61-
if (ncfile_domain.locations[i].run < global_domain.locations[i].run) {
62-
log_err("parameter file mask for gridcell %zu is zero and the "
63-
"domain file specifies that this cell should be run", i);
64-
}
6564
// latitude matches
6665
if (!assert_close_double(ncfile_domain.locations[i].latitude,
6766
global_domain.locations[i].latitude,

0 commit comments

Comments
 (0)