def get_area_def(hdf_file): generic_m3 = str(hdf_file) metadata = parseMeta(generic_m3) # Read the lats and lons from the MYD03 file print(f'reading {generic_m3}') m3_file = SD(str(generic_m3), SDC.READ) lats = m3_file.select('Latitude').get() lons = m3_file.select('Longitude').get() m3_file.end() proj_params = get_proj_params(generic_m3) swath_def = SwathDefinition(lons, lats) area_def = swath_def.compute_optimal_bb_area(proj_dict=proj_params) return (area_def, lons, lats, metadata, swath_def)
def main(): """ run the test """ generic_m3 = a301.data_dir / Path("m3_file_2018_10_1.hdf") if not generic_m3.exists(): raise ValueError(f"couldn't find {generic_m3}") modis_meta = parseMeta(generic_m3) print(f"working on {generic_m3}, originally was { modis_meta['filename']}") m3_file = SD(str(generic_m3), SDC.READ) lats = m3_file.select('Latitude').get() lons = m3_file.select('Longitude').get() stars = '*' * 40 print( f"{stars}\nlats.shape, lons.shape: {lats.shape},{lons.shape}\n{stars}") m3_file.end() generic_rad = a301.data_dir / Path("rad_file_2018_10_1.hdf") if not generic_rad.exists(): raise ValueError(f"couldn't find {generic_rad}") rad_file = SD(str(generic_rad), SDC.READ) ch30 = rad_file.select('ch30').get() print(f"working on {generic_rad}, originally was {rad_file.filename}") print(f"{stars}\narray shape is: {ch30.shape}\n{stars}") rad_file.end() print(f'reading {generic_m3}') from pyresample import SwathDefinition proj_params = get_proj_params(generic_m3) swath_def = SwathDefinition(lons, lats) area_def = swath_def.compute_optimal_bb_area(proj_dict=proj_params) fill_value = -9999. area_name = 'modis swath 5min granule' image_30 = kd_tree.resample_nearest(swath_def, ch30.ravel(), area_def, radius_of_influence=5000, nprocs=2, fill_value=fill_value) print(f'\ndump area definition:\n{area_def}\n') print((f'\nx and y pixel dimensions in meters:' f'\n{area_def.pixel_size_x}\n{area_def.pixel_size_y}\n'))
def runit(): from pyresample import SwathDefinition, kd_tree, geometry proj_params = get_proj_params(m5_file) swath_def = SwathDefinition(lons_5km, lats_5km) area_def_lr = swath_def.compute_optimal_bb_area(proj_dict=proj_params) area_def_lr.name = "ir wv retrieval modis 5 km resolution (lr=low resolution)" area_def_lr.area_id = 'modis_ir_wv' area_def_lr.job_id = area_def_lr.area_id fill_value = -9999. image_wv_ir = kd_tree.resample_nearest(swath_def, wv_ir_scaled.ravel(), area_def_lr, radius_of_influence=5000, nprocs=2, fill_value=fill_value) image_wv_ir[image_wv_ir < -9000] = np.nan print(f'\ndump area definition:\n{area_def_lr}\n') print((f'\nx and y pixel dimensions in meters:' f'\n{area_def_lr.pixel_size_x}\n{area_def_lr.pixel_size_y}\n')) pdb.set_trace()
def main(): """ run the test """ stars = '*' * 50 print(f'\n{stars}\nrunning test: {__file__}\n{stars}\n') generic_m3 = a301.data_dir / Path("m3_file_2018_10_1.hdf") if not generic_m3.exists(): raise ValueError(f"couldn't find {generic_m3}") modis_meta = parseMeta(generic_m3) print(f"working on {generic_m3}, originally was { modis_meta['filename']}") m3_file = SD(str(generic_m3), SDC.READ) lats_1km = m3_file.select('Latitude').get() lons_1km = m3_file.select('Longitude').get() stars = '*' * 40 print( f"{stars}\nlats_1km.shape, lons_1km.shape: {lats_1km.shape},{lons_1km.shape}\n{stars}" ) m3_file.end() generic_m5 = a301.data_dir / Path("myd05_l2_10_7.hdf") if not generic_m5.exists(): raise ValueError(f"couldn't find {generic_m5}") m5_file = SD(str(generic_m5), SDC.READ) vapor_ir = m5_file.select('Water_Vapor_Infrared').get() vapor_near_ir = m5_file.select('Water_Vapor_Near_Infrared').get() lats_5km = m5_file.select('Latitude').get() lons_5km = m5_file.select('Longitude').get() m5_file.end() print('through') m5_meta = parseMeta(generic_m5) print(f"working on {generic_m5}, originally was {m5_meta['filename']}") print( f"{stars}\nnearir vapor array shape is: {vapor_near_ir.shape}\n{stars}" ) print(f"{stars}\nir vapor array shape is: {vapor_ir.shape}\n{stars}") print(f"{stars}\nlats_5km arrayshape is: {lats_5km.shape}\n{stars}") print(f"{stars}\nlons_5km arrayshape is: {lons_5km.shape}\n{stars}") # print(f'reading {generic_m3}') from pyresample import SwathDefinition proj_params = get_proj_params(generic_m3) swath_def = SwathDefinition(lons_1km, lats_1km) area_def = swath_def.compute_optimal_bb_area(proj_dict=proj_params) fill_value = -9999. area_name = 'modis swath 5min granule' image_nearir = kd_tree.resample_nearest(swath_def, vapor_near_ir.ravel(), area_def, radius_of_influence=5000, nprocs=2, fill_value=fill_value) print( f'was able to regrid the nearir image, xy shape is {image_nearir.shape}' ) proj_params = get_proj_params(generic_m5) swath_def = SwathDefinition(lons_5km, lats_5km) area_def = swath_def.compute_optimal_bb_area(proj_dict=proj_params) fill_value = -9999. area_name = 'modis swath 5min granule' image_ir = kd_tree.resample_nearest(swath_def, vapor_ir.ravel(), area_def, radius_of_influence=5000, nprocs=2, fill_value=fill_value) print(f'was able to regrid the ir image, xy shape is {image_ir.shape}') print('data looks good, ready to go')
# Read the lats and lons from the MYD03 file print(f'reading {generic_m3}') m3_file = SD(str(generic_m3), SDC.READ) lats = m3_file.select('Latitude').get() lons = m3_file.select('Longitude').get() m3_file.end() dir(metadata) # %% {"scrolled": true} from pyresample import load_area, save_quicklook, SwathDefinition proj_params = get_proj_params(generic_m3) swath_def = SwathDefinition(lons, lats) area_def = swath_def.compute_optimal_bb_area(proj_dict=proj_params) area_def # %% print(swath_def.shape) print(area_def.shape) # %% {"scrolled": false} #p_utm = Proj(crs) p_lonlat = Proj(proj='latlong', datum='WGS84') stn_lon = -105.237 stn_lat = 40.125 stn_x, stn_y = proj_transform(p_lonlat, Proj(area_def.proj_dict), stn_lon, stn_lat) min_x, min_y = proj_transform(p_lonlat, Proj(area_def.proj_dict), metadata['min_lon'], metadata['min_lat'])
# the low resolution (lr) image. The cell below let's pyresample create the # area_def object, which we will reuse for the 1 km watervapor retrieval to # get both onto the same grid. # # The cell below produces: # # * `image_wv_ir` -- resampled 5 km infrared water vapor # * `area_def_lr` -- area_def used for the resample # %% from pyresample import SwathDefinition, kd_tree, geometry proj_params_5km = get_proj_params(m5_file_str) proj_params_1km = get_proj_params(m3_file_str) swath_def = SwathDefinition(lons_5km, lats_5km) area_def_lr = swath_def.compute_optimal_bb_area(proj_dict=proj_params_5km) #area_def_lr.name = "ir wv retrieval modis 5 km resolution (lr=low resolution)" #area_def_lr.area_id = "modis_ir_wv" #area_def_lr.job_id = area_def_lr.area_id fill_value = -9999.0 image_wv_ir = kd_tree.resample_nearest( swath_def, wv_ir_scaled.ravel(), area_def_lr, radius_of_influence=5000, nprocs=2, fill_value=fill_value, ) image_wv_ir[image_wv_ir < -9000] = np.nan print(f"\ndump area definition:\n{area_def_lr}\n") print(