-
Notifications
You must be signed in to change notification settings - Fork 41
return delay files in geo coords if geocoded aoi #408
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
bbuzzanga
wants to merge
2
commits into
dbekaert:dev
Choose a base branch
from
bbuzzanga:projection_bugs
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -118,7 +118,7 @@ def tropo_delay(dt, wetFilename, hydroFilename, args): | |
|
|
||
| ########################################################### | ||
| # Load the downloaded model file for CRS information | ||
| wm_proj = rio_profile(f"netcdf:{weather_model_file}:t")["crs"] | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same thing here as above, and below as well. |
||
| wm_proj = rio_profile(f"netcdf:{weather_model_file}:t")[0]["crs"] | ||
| if wm_proj is None: | ||
| print("WARNING: I can't find a CRS in the weather model file, so I will assume you are using WGS84") | ||
| wm_proj = CRS.from_epsg(4326) | ||
|
|
@@ -282,7 +282,7 @@ def tropo_delay_cube(dt, wf, args, model_file=None): | |
| logger.debug(f'Output height range is {min(heights)} to {max(heights)}') | ||
|
|
||
| # Load CRS from weather model file | ||
| wm_proj = rio_profile(f"netcdf:{weather_model_file}:t")["crs"] | ||
| wm_proj = rio_profile(f"netcdf:{weather_model_file}:t")[0]["crs"] | ||
| if wm_proj is None: | ||
| print("WARNING: I can't find a CRS in the weather model file, so I will assume you are using WGS84") | ||
| wm_proj = CRS.from_epsg(4326) | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,6 +23,9 @@ | |
| from RAiDER.logger import logger | ||
|
|
||
|
|
||
| pbar = None | ||
|
|
||
|
|
||
| def projectDelays(delay, inc): | ||
| '''Project zenith delays to LOS''' | ||
| return delay / cosd(inc) | ||
|
|
@@ -120,7 +123,13 @@ def rio_profile(fname): | |
| f"{fname} does not contain geotransform information" | ||
| ) | ||
|
|
||
| return profile | ||
| elif profile['crs'].to_epsg() != 4326: | ||
| fname_wgs84 = rio_reproject_geocoded(fname) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this the part that wasn't working to correctly reproject the outputs? |
||
| with rasterio.open(fname_wgs84) as src: | ||
| profile = src.profile | ||
| fname = fname_wgs84 | ||
|
|
||
| return profile, fname | ||
|
|
||
|
|
||
| def rio_extents(profile): | ||
|
|
@@ -244,7 +253,7 @@ def writeArrayToRaster(array, filename, noDataValue=0., fmt='ENVI', proj=None, g | |
| ''' | ||
| array_shp = np.shape(array) | ||
| if array.ndim != 2: | ||
| raise RuntimeError('writeArrayToRaster: cannot write an array of shape {} to a raster image'.format(array_shp)) | ||
| raise RuntimeError(f'writeArrayToRaster: cannot write an array of shape {array_shp} to a raster image') | ||
|
|
||
| # Data type | ||
| if "complex" in str(array.dtype): | ||
|
|
@@ -439,6 +448,12 @@ def writeDelays(aoi, wetDelay, hydroDelay, lats, lons, | |
| wetDelay[np.isnan(wetDelay)] = ndv | ||
| hydroDelay[np.isnan(hydroDelay)] = ndv | ||
|
|
||
| try: | ||
| proj, gt = aoi._proj, aoi._gt | ||
| except: | ||
| proj, gt = None, None | ||
|
|
||
|
|
||
| # Do different things, depending on the type of input | ||
| if aoi.type() == 'station_file': | ||
| try: | ||
|
|
@@ -451,6 +466,7 @@ def writeDelays(aoi, wetDelay, hydroDelay, lats, lons, | |
| df['totalDelay'] = wetDelay + hydroDelay | ||
| df.to_csv(wetFilename, index=False) | ||
|
|
||
|
|
||
| elif outformat == 'hdf5': | ||
| writeResultsToHDF5( | ||
| lats, | ||
|
|
@@ -966,9 +982,6 @@ def read_EarthData_loginInfo(filepath=None): | |
| return urs_usr, urs_pwd | ||
|
|
||
|
|
||
| pbar = None | ||
|
|
||
|
|
||
| def show_progress(block_num, block_size, total_size): | ||
| global pbar | ||
| if pbar is None: | ||
|
|
@@ -1075,3 +1088,37 @@ def calcgeoh(lnsp, t, q, z, a, b, R_d, num_levels): | |
| z_h += TRd * dlogP | ||
|
|
||
| return geopotential, pressurelvs, geoheight | ||
|
|
||
|
|
||
| def rio_reproject_geocoded(fname, epsg=4326): | ||
| """ Reproject the input geocoded file to 4326 | ||
|
|
||
| Write a new geocoded file with with suffix .WGS84 | ||
| Required so weather model bounds align | ||
| https://rasterio.readthedocs.io/en/latest/topics/reproject.html | ||
| """ | ||
| dst_crs = f'EPSG:{epsg}' | ||
| dst_fname = f'{fname}.WGS84' | ||
|
|
||
| with rasterio.open(fname) as src: | ||
| transform, width, height = rasterio.warp.calculate_default_transform( | ||
| src.crs, dst_crs, src.width, src.height, *src.bounds) | ||
| kwargs = src.meta.copy() | ||
| kwargs.update({ | ||
| 'crs': dst_crs, | ||
| 'transform': transform, | ||
| 'width': width, | ||
| 'height': height | ||
| }) | ||
|
|
||
| with rasterio.open(dst_fname, 'w', **kwargs) as dst: | ||
| for i in range(1, src.count + 1): | ||
| rasterio.warp.reproject( | ||
| source=rasterio.band(src, i), | ||
| destination=rasterio.band(dst, i), | ||
| src_transform=src.transform, | ||
| src_crs=src.crs, | ||
| dst_transform=transform, | ||
| dst_crs=dst_crs, | ||
| resampling=rasterio.warp.Resampling.nearest) | ||
| return dst_fname | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we add a try/except here so either will work? Or is it always [0]?