Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 13 additions & 6 deletions tools/gridmet/gridmet_daily_ppt.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,9 +191,16 @@ def main(start_dt, end_dt, netcdf_ws, ancillary_ws, output_ws,
# Read in the GRIDMET NetCDF file
# Immediately clip input array to save memory
input_nc_f = netCDF4.Dataset(input_raster, 'r')
input_nc = input_nc_f.variables[gridmet_band_dict[input_var]][
:, row_a: row_b, col_a: col_b].copy()
input_nc = np.flip(input_nc, 1)
if input_nc_f.file_format == 'NETCDF3_CLASSIC':
input_nc = input_nc_f.variables[gridmet_band_dict[input_var]][
:, row_a: row_b, col_a: col_b].copy()
input_nc = np.flip(input_nc, 1)
elif input_nc_f.file_format == 'NETCDF4':
input_nc = np.flip(input_nc_f.variables[gridmet_band_dict[input_var]], 1)
input_nc = input_nc[:, row_a: row_b, col_a: col_b].copy()
input_nc = np.flip(input_nc, 1)
else:
raise TypeError('The netcdf file {} format is invalid'.format(input_raster))
input_nc_f.close()
del input_nc_f

Expand Down Expand Up @@ -266,9 +273,9 @@ def main(start_dt, end_dt, netcdf_ws, ancillary_ws, output_ws,

def arg_parse():
"""Base all default folders from script location
scripts: ./pymetric/tools/gridmet
tools: ./pymetric/tools
output: ./pymetric/gridmet
scripts: ./pymetric_/tools/gridmet
tools: ./pymetric_/tools
output: ./pymetric_/gridmet
"""
script_folder = sys.path[0]
code_folder = os.path.dirname(script_folder)
Expand Down
37 changes: 27 additions & 10 deletions tools/gridmet/gridmet_daily_refet.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@
import netCDF4
import numpy as np
from osgeo import gdal
# import refet

import _utils


# import refet


def main(start_dt, end_dt, netcdf_ws, ancillary_ws, output_ws,
etr_flag=False, eto_flag=False, extent_path=None, output_extent=None,
stats_flag=True, overwrite_flag=False, scalar=None):
Expand Down Expand Up @@ -248,17 +250,32 @@ def main(start_dt, end_dt, netcdf_ws, ancillary_ws, output_ws,
if eto_flag:
logging.debug(" {}".format(eto_path))
eto_nc_f = netCDF4.Dataset(eto_path, 'r')
eto_nc = eto_nc_f.variables[gridmet_band_dict['eto']][
:, row_a: row_b, col_a: col_b].copy()
eto_nc = np.flip(eto_nc, 1)
if eto_nc_f.file_format == 'NETCDF3_CLASSIC':
eto_nc = eto_nc_f.variables[gridmet_band_dict['eto']][
:, row_a: row_b, col_a: col_b].copy()
eto_nc = np.flip(eto_nc, 1)
elif eto_nc_f.file_format == 'NETCDF4':
eto_nc = np.flip(eto_nc_f.variables[gridmet_band_dict['etr']], 1)
eto_nc = eto_nc[:, row_a: row_b, col_a: col_b].copy()
eto_nc = np.flip(eto_nc, 1)
else:
raise TypeError('The netcdf file {} format is invalid'.format(eto_path))
eto_nc_f.close()
del eto_nc_f

if etr_flag:
logging.debug(" {}".format(etr_path))
etr_nc_f = netCDF4.Dataset(etr_path, 'r')
etr_nc = etr_nc_f.variables[gridmet_band_dict['etr']][
:, row_a: row_b, col_a: col_b].copy()
etr_nc = np.flip(etr_nc, 1)
if etr_nc_f.file_format == 'NETCDF3_CLASSIC':
etr_nc = etr_nc_f.variables[gridmet_band_dict['etr']][
:, row_a: row_b, col_a: col_b].copy()
etr_nc = np.flip(etr_nc, 1)
elif etr_nc_f.file_format == 'NETCDF4':
etr_nc = np.flip(etr_nc_f.variables[gridmet_band_dict['etr']], 1)
etr_nc = etr_nc[:, row_a: row_b, col_a: col_b].copy()
etr_nc = np.flip(etr_nc, 1)
else:
raise TypeError('The netcdf file {} format is invalid'.format(eto_path))
etr_nc_f.close()
del etr_nc_f

Expand Down Expand Up @@ -624,9 +641,9 @@ def main(start_dt, end_dt, netcdf_ws, ancillary_ws, output_ws,

def arg_parse():
"""Base all default folders from script location
scripts: ./pymetric/tools/gridmet
tools: ./pymetric/tools
output: ./pymetric/gridmet
scripts: ./pymetric_/tools/gridmet
tools: ./pymetric_/tools
output: ./pymetric_/gridmet
"""
script_folder = sys.path[0]
code_folder = os.path.dirname(script_folder)
Expand Down