-
Notifications
You must be signed in to change notification settings - Fork 1
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
[BUG] gridding_plot only work for global and WGS84 currently #54
Comments
Hi @juangallegozamorano !
|
Hi @chenyangkang, I accessed the |
@juangallegozamorano There is not function implemented for this in stemflow. But you can do: from stemflow.utils.jitterrotation.jitterrotator import JitterRotator
from shapely.geometry import Polygon
import geopandas as gpd
# define a function
def geo_grid_geometry(line):
old_x, old_y = JitterRotator.inverse_jitter_rotate(
[line['stixel_calibration_point_transformed_left_bound'], line['stixel_calibration_point_transformed_left_bound'], line['stixel_calibration_point_transformed_right_bound'], line['stixel_calibration_point_transformed_right_bound']],
[line['stixel_calibration_point_transformed_lower_bound'], line['stixel_calibration_point_transformed_upper_bound'], line['stixel_calibration_point_transformed_upper_bound'], line['stixel_calibration_point_transformed_lower_bound']],
line['rotation'],
line['calibration_point_x_jitter'],
line['calibration_point_y_jitter'],
)
polygon = Polygon(list(zip(old_x, old_y)))
return polygon
# Make a geometry attribute for each stixel
model.ensemble_df['geometry'] = model.ensemble_df.apply(geo_grid_geometry, axis=1)
model.ensemble_df = gpd.GeoDataFrame(model.ensemble_df, geometry='geometry') Which creates a spatial object for each stixel. Then: model.ensemble_df.plot(alpha=0.2) The stixel will stack on the temporal dimension. You may want to pick only one time range (since the spatial splitting pattern will be the same for all temporal windows in one ensemble). model.ensemble_df[
(model.ensemble_df['DOY_start']>=90) & (model.ensemble_df['DOY_start']<120)
].plot(alpha=0.2) Which will look less messy. You may also want to add scatter points on top of this: fig,ax = plt.subplots()
model.ensemble_df[
(model.ensemble_df['DOY_start']>=90) & ((model.ensemble_df['DOY_start']<120))
].plot(alpha=0.2,ax=ax)
ax.scatter(
X_train['longitude'],
X_train['latitude'],
c='tab:orange',s=0.2,alpha=0.7
)
plt.show() Cheers! |
Thanks a lot!! This is really helpful! |
Hi @chenyangkang, for some reason the geometries are all empty in my case... |
@juangallegozamorano You could provide details e.g. the model.ensemble_df original data frame for debugging purpose. |
Here are two examples of ensemble_df that I would like to represent in a figure |
@juangallegozamorano I cannot reproduce the bug. This is what I got for data = pd.read_csv('53970_larcan_ensemble_grid.csv', index_col=0)
from stemflow.utils.jitterrotation.jitterrotator import JitterRotator
from shapely.geometry import Polygon
import geopandas as gpd
# define a function
def geo_grid_geometry(line):
old_x, old_y = JitterRotator.inverse_jitter_rotate(
[line['stixel_calibration_point_transformed_left_bound'], line['stixel_calibration_point_transformed_left_bound'], line['stixel_calibration_point_transformed_right_bound'], line['stixel_calibration_point_transformed_right_bound']],
[line['stixel_calibration_point_transformed_lower_bound'], line['stixel_calibration_point_transformed_upper_bound'], line['stixel_calibration_point_transformed_upper_bound'], line['stixel_calibration_point_transformed_lower_bound']],
line['rotation'],
line['calibration_point_x_jitter'],
line['calibration_point_y_jitter'],
)
polygon = Polygon(list(zip(old_x, old_y)))
return polygon
# Make a geometry attribute for each stixel
data['geometry'] = data.apply(geo_grid_geometry, axis=1)
data = gpd.GeoDataFrame(data, geometry='geometry') |
I also successfully plotted the add a "print" line in the function: def geo_grid_geometry(line):
old_x, old_y = JitterRotator.inverse_jitter_rotate(
[line['stixel_calibration_point_transformed_left_bound'], line['stixel_calibration_point_transformed_left_bound'], line['stixel_calibration_point_transformed_right_bound'], line['stixel_calibration_point_transformed_right_bound']],
[line['stixel_calibration_point_transformed_lower_bound'], line['stixel_calibration_point_transformed_upper_bound'], line['stixel_calibration_point_transformed_upper_bound'], line['stixel_calibration_point_transformed_lower_bound']],
line['rotation'],
line['calibration_point_x_jitter'],
line['calibration_point_y_jitter'],
)
polygon = Polygon(list(zip(old_x, old_y)))
print(polygon) # this line should print out the polygon string.
return polygon |
I just tried again and now I can see the stixels...I cannot explain why there were empty geometries before, thanks a lot and sorry for the hassle! |
No worries! Good to hear you solved it! |
Hi @chenyangkang,
Exporting the plot for the grid of the quadtrees only works when using WGS84. Is there a way to access the grid itself and or export the figure under another CRS?
Thanks!
The text was updated successfully, but these errors were encountered: