def run(input_root, simulation_period): paths.build(input_root) amf_dict = amf_obs_time_series(BASE_AMF_DICT, complete_days_only=True, return_low_err=True) # get_etrm_time_series(paths.amf_extract, dict_=amf_dict) for k, v in amf_dict.iteritems(): for kk, vv in v.iteritems(): if isinstance(vv, DataFrame): p = os.path.join(paths.amf_output_root, '{}_{}.csv'.format(k, kk)) print 'writing to {}'.format(p) vv.to_csv(p) val = amf_dict.values()[0] cfg = Config() for runspec in cfg.runspecs: paths.build(runspec.input_root, runspec.output_root) etrm = Processes(runspec) etrm.configure_run(runspec) etrm.run() save_run(etrm, val)
def main(): paths.build('F:') startday = datetime(2013, 12, 17, 0) endday = datetime(2013, 12, 31, 0) finalyear = 2013 base_dir = paths.ndvi_individ output = paths.ndvi_spline year = '2000' ref_map = os.path.join(base_dir, year, 'NDVI2000_01_01.tif') _, _, _, _, lon, lat, linke, prj, fill_val = read_map(ref_map, 'Gtiff') srs = osr.SpatialReference(prj) sr_wkt = srs.ExportToWkt() for day in rrule.rrule(rrule.DAILY, dtstart=startday, until=endday): nr = day.strftime('%j') year = day.strftime('%Y') # ndvi_daily = time_interpolation(day, lat, lon, finalyear) ndvi_daily = time_interpolation(base_dir, day, finalyear) # Write daily values to new daily rasters daily_doy = 'ndvi{}_{}.tif'.format(year, nr) outpath = os.path.join(output, year) if not os.path.exists(outpath): os.makedirs(outpath) outname = os.path.join(outpath, daily_doy) write_map(outname, 'Gtiff', lon, lat, ndvi_daily, sr_wkt, fill_val)
def main(): paths.build('F:') startday = datetime(2013, 12, 17, 0) endday = datetime(2013, 12, 31, 0) finalyear = 2013 base_dir = paths.ndvi_individ output = paths.ndvi_spline year = '2000' ref_map = os.path.join(base_dir, year, 'NDVI2000_01_01.tif') _, _, _, _, lon, lat, linke, prj, fill_val = read_map(ref_map, 'Gtiff') srs = osr.SpatialReference(prj) sr_wkt = srs.ExportToWkt() for day in rrule.rrule(rrule.DAILY, dtstart=startday, until=endday): nr = day.strftime('%j') year = day.strftime('%Y') # ndvi_daily = time_interpolation(day, lat, lon, finalyear) ndvi_daily = time_interpolation(base_dir, day, finalyear) # Write daily values to new daily rasters daily_doy = 'ndvi{}_{}.tif'.format(year, nr) outpath = os.path.join(output, year) if not os.path.exists(outpath): os.makedirs(outpath) outname = os.path.join(outpath, daily_doy) write_map(outname, 'Gtiff', lon, lat, ndvi_daily, sr_wkt, fill_val)
def run_dataset(): print('Running Dataset') cfg = Config() for runspec in cfg.runspecs: paths.build(runspec.input_root, runspec.output_root) paths.set_mask_path(runspec.mask) generate_dataset(runspec.date_range, runspec.output_root)
def run_model(cfg_path=None): print('Running Model') print('supplied cfg_path {}'.format(cfg_path)) cfg = Config(cfg_path) print('Using configuration from {}'.format(cfg.path)) for i, runspec in enumerate(cfg.runspecs): print('Using mask path {}'.format(runspec.mask)) runspec.output_root = '{}{:03n}'.format(runspec.output_root, i) # TODO - make a modified make_results_dir to only create of the 'outer' folder. make_results_dir(runspec.output_root) paths.build(runspec.input_root, runspec.output_root) etrm = Processes(runspec) etrm.configure_run(runspec) etrm.run()
def extract_etrm_point_inputs(input_root, output_root, simulation_period): # ndvi_path = os.path.join(input_root, 'NDVI', 'NDVI_std_all') # prism_path = os.path.join(input_root, 'PRISM') # penman_path = os.path.join(input_root, 'PM_RAD') paths.build(input_root) # statics = os.path.join(input_root, 'statics') # sa_path = os.path.join(input_root, 'shapefiles') # (input_root, 'shapefiles') # sb_path is where the outputs are going. sa_path used to be for sensitivity analysis. # sb_path = os.path.join(input_root, 'ameriflux_ex_sac') # ameriflux_sites # save_path = sb_path # os.path.join(sa_path, 'AMF_extracts') # save_path = sb_path # os.path.join(sa_path, 'AMF_extracts') shapefile = os.path.join('/Users', 'Gabe', 'Desktop', 'QGIS_Ameriflux', 'coords_attempt3.shp') # shape = os.path.join(sa_path, 'amf_sites_UTM.shp') print(("Here is the save path {}".format(output_root))) get_dynamic_inputs_from_shape(shapefile, simulation_period, output_root)
def extract_etrm_point_inputs(input_root, output_root, simulation_period): # ndvi_path = os.path.join(input_root, 'NDVI', 'NDVI_std_all') # prism_path = os.path.join(input_root, 'PRISM') # penman_path = os.path.join(input_root, 'PM_RAD') paths.build(input_root) # statics = os.path.join(input_root, 'statics') # sa_path = os.path.join(input_root, 'shapefiles') # (input_root, 'shapefiles') # sb_path is where the outputs are going. sa_path used to be for sensitivity analysis. # sb_path = os.path.join(input_root, 'ameriflux_ex_sac') # ameriflux_sites # save_path = sb_path # os.path.join(sa_path, 'AMF_extracts') # save_path = sb_path # os.path.join(sa_path, 'AMF_extracts') shapefile = os.path.join('/Users', 'Gabe', 'Desktop', 'QGIS_Ameriflux', 'coords_attempt3.shp') # shape = os.path.join(sa_path, 'amf_sites_UTM.shp') print("Here is the save path {}".format(output_root)) get_dynamic_inputs_from_shape(shapefile, simulation_period, output_root)
def run(): paths.build('F:') penman_example = 'PM_NM_2000_001.tif' map_for_reference = os.path.join(paths.penman, '2000', penman_example) _, _, _, _, x, y, _, prj, fill_val = read_map(map_for_reference, 'Gtiff') start = datetime.datetime(2000, 1, 1, 0) end = datetime.datetime(2001, 12, 31, 0) fill_val = -999. for day in rrule.rrule(rrule.DAILY, dtstart=start, until=end): year = day.strftime('%Y') month = day.strftime('%m') day_mth = day.strftime('%d') # yearstr = str(year) # output = os.path.join(output_dir, new_dir, year) # print(output_dir) ndvi = get_kcb(paths.ndvi_std_all, day) # kcb = remake_array(mask_path, kcb) ndvi[ndvi == fill_val] = 0 # print(ndvi, ndvi.shape) new_ndvi = 'NDVI{}_{}_{}.tif'.format(year, month, day_mth) output_dir = os.path.join(paths.etrm_input_root, 'NDVI_individ', str(year)) ndvi_out = os.path.join(output_dir, new_ndvi) if not os.path.isdir(output_dir): os.makedirs(output_dir) print(('Saving New NDVI file as {}'.format(ndvi_out))) write_map(ndvi_out, 'Gtiff', x, y, ndvi, prj, fill_val)
def run(): paths.build('F:') penman_example = 'PM_NM_2000_001.tif' map_for_reference = os.path.join(paths.penman, '2000', penman_example) _, _, _, _, x, y, _, prj, fill_val = read_map(map_for_reference, 'Gtiff') start = datetime.datetime(2000, 1, 1, 0) end = datetime.datetime(2001, 12, 31, 0) fill_val = -999. for day in rrule.rrule(rrule.DAILY, dtstart=start, until=end): year = day.strftime('%Y') month = day.strftime('%m') day_mth = day.strftime('%d') # yearstr = str(year) # output = os.path.join(output_dir, new_dir, year) # print(output_dir) ndvi = get_kcb(paths.ndvi_std_all, day) # kcb = remake_array(mask_path, kcb) ndvi[ndvi == fill_val] = 0 # print(ndvi, ndvi.shape) new_ndvi = 'NDVI{}_{}_{}.tif'.format(year, month, day_mth) output_dir = os.path.join(paths.etrm_input_root, 'NDVI_individ', str(year)) ndvi_out = os.path.join(output_dir, new_ndvi) if not os.path.isdir(output_dir): os.makedirs(output_dir) print('Saving New NDVI file as {}'.format(ndvi_out)) write_map(ndvi_out, 'Gtiff', x, y, ndvi, prj, fill_val)
def run(input_root, coords_path): paths.build(input_root) # a function that takes uses GDAL to get the coordinates of points. point_dict = get_point_dict(coords_path) simulation_period = datetime(2007, 1, 1), datetime(2013, 12, 29) get_etrm_time_series(paths.amf_ex_sac_extract, dict_=point_dict) print 'amf dict w/ etrm input time series: \n{}'.format(point_dict) # fix this so it appends to all sites output = os.path.join(paths.amf_ex_sac_output_root, 'trackers') for key, val in point_dict.iteritems(): # TODO: use of point dicts no longer supported by Processes. need to update accordingly to use masks. # ================================================================= # instantiate for each item to get a clean master dict etrm = Processes(simulation_period, paths.amf_trackers, point_dict=point_dict) print 'point dict, pre-etrm run {}'.format(point_dict) # for testing print 'key : {}'.format(key) # ================================================================= # TODO: `run` does not return anything. need different way to access tracker. # probably not even necessary as tracker results are saved at the end of `run` tracker = etrm.run(simulation_period, point_dict=point_dict, point_dict_key=key, modify_soils=True, ro_reinf_frac=0.7, allen_ceff=0.8) # print 'tracker after etrm run: \n {}'.format(tracker) csv_path_filename = os.path.join(output, '{}.csv'.format(val['Name'])) print 'this should be your csv: {}'.format(csv_path_filename) # saves the model results to the tracker. Keep this part. tracker.to_csv(csv_path_filename, na_rep='nan', index_label='Date')
def slice_and_save(p, arr, geo, startc, endc, startr, endr): if not os.path.isdir(os.path.dirname(p)): os.makedirs(os.path.dirname(p)) raster = Raster.fromarray(arr) marr = raster.unmasked() marr = marr[slice(startr, endr), slice(startc, endc)] # print 'saving {}'.format(p) raster.save(p, marr, geo) def make_reduced_path(out, tag, k): p = os.path.join(out, tag) # if not os.path.isdir(p): # os.makedirs(p) p = os.path.join(p, '{}_reduced.tif'.format(k)) return p def get_transform(startc, startr): transform = get_tiff_transform(paths.mask) transform *= Affine.translation(startc, startr) transform = transform.to_gdal() return transform if __name__ == '__main__': paths.build('/Volumes/Seagate Expansion Drive/ETRM_inputs') generate_dataset(['1/1/2000', '12/31/2013'], '/Volumes/Seagate Expansion Drive/gabe_aoi_inputs') # ============= EOF =============================================
def slice_and_save(p, arr, geo, startc, endc, startr, endr): if not os.path.isdir(os.path.dirname(p)): os.makedirs(os.path.dirname(p)) raster = Raster.fromarray(arr) marr = raster.unmasked() marr = marr[slice(startr, endr), slice(startc, endc)] # print 'saving {}'.format(p) raster.save(p, marr, geo) def make_reduced_path(out, tag, k): p = os.path.join(out, tag) # if not os.path.isdir(p): # os.makedirs(p) p = os.path.join(p, '{}_reduced.tif'.format(k)) return p def get_transform(startc, startr): transform = get_tiff_transform(paths.mask) transform *= Affine.translation(startc, startr) transform = transform.to_gdal() return transform if __name__ == '__main__': paths.build('/Volumes/Seagate Expansion Drive/ETRM_inputs') generate_dataset(['1/1/2000', '12/31/2013'], '/Volumes/Seagate Expansion Drive/gabe_aoi_inputs') # ============= EOF =============================================