-
Notifications
You must be signed in to change notification settings - Fork 4
DAS-2238 - updates to enable 3D variables without dimension scales to… #27
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
Changes from 2 commits
ce0172b
d0569a4
b9d3fe6
31d8b16
97c2720
e1dba8c
7614f4c
601344d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -60,8 +60,13 @@ def get_variables_with_anonymous_dims( | |
return set( | ||
variable | ||
for variable in variables | ||
if (len(varinfo.get_variable(variable).dimensions) == 0) | ||
or (any_absent_dimension_variables(varinfo, variable)) | ||
if ( | ||
varinfo.get_variable(variable) | ||
and ( | ||
(len(varinfo.get_variable(variable).dimensions) == 0) | ||
or (any_absent_dimension_variables(varinfo, variable)) | ||
) | ||
) | ||
) | ||
|
||
|
||
|
@@ -70,42 +75,56 @@ def any_absent_dimension_variables(varinfo: VarInfoFromDmr, variable: str) -> bo | |
that have been created by opendap, but are not really | ||
dimension variables | ||
""" | ||
|
||
return any( | ||
varinfo.get_variable(dimension) is None | ||
for dimension in varinfo.get_variable(variable).dimensions | ||
) | ||
|
||
|
||
def get_dimension_array_names_from_coordinate_variables( | ||
def get_dimension_array_names( | ||
varinfo: VarInfoFromDmr, | ||
variable_name: str, | ||
) -> list[str]: | ||
""" | ||
Returns the dimensions names from coordinate variables | ||
Returns the dimensions names from coordinate variables or from | ||
configuration | ||
""" | ||
variable = varinfo.get_variable(variable_name) | ||
dimension_names = varinfo.get_variable(variable_name).dimensions | ||
|
||
if len(dimension_names) >= 2: | ||
# if the dimension is not a variable, was added as a | ||
# configuration entry, | ||
D-Auty marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
if variable is not None: | ||
joeyschultz marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
return dimension_names | ||
D-Auty marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
latitude_coordinates, longitude_coordinates = get_coordinate_variables( | ||
varinfo, [variable_name] | ||
) | ||
|
||
# for one variable, the coordinate array length will always be 1 or 0 | ||
if len(latitude_coordinates) == 1 and len(longitude_coordinates) == 1: | ||
dimension_array_names = get_dimension_array_names( | ||
dimension_array_names = get_dimension_array_names_from_coordinates( | ||
varinfo, latitude_coordinates[0] | ||
) | ||
# if variable does not have coordinates (len = 0) | ||
elif ( | ||
varinfo.get_variable(variable_name).is_latitude() | ||
or varinfo.get_variable(variable_name).is_longitude() | ||
): | ||
dimension_array_names = get_dimension_array_names(varinfo, variable_name) | ||
dimension_array_names = get_dimension_array_names_from_coordinates( | ||
varinfo, variable_name | ||
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. The comment says 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. but the variable itself is a coordinate. So we are using the coordinate to name it. Will update the comment 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. updated comment - b9d3fe6 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. Sorry that the logic here still confuses me, and yes coordinates have coordinates - so that is a bit confusing. So... In both cases above - function should be: create_dimension_array_names_for_coorrdinate. 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. updated - 7614f4c |
||
) | ||
else: | ||
dimension_array_names = [] | ||
|
||
return dimension_array_names | ||
|
||
|
||
def get_dimension_array_names(varinfo: VarInfoFromDmr, variable_name: str) -> str: | ||
def get_dimension_array_names_from_coordinates( | ||
|
||
varinfo: VarInfoFromDmr, variable_name: str | ||
) -> str: | ||
"""returns the x-y variable names that would | ||
match the group of the input variable. The 'dim_y' dimension | ||
and 'dim_x' names are returned with the group pathname | ||
|
@@ -172,13 +191,19 @@ def create_dimension_arrays_from_coordinates( | |
col_dim_values, np.transpose(col_indices)[1], col_size | ||
) | ||
|
||
projected_y, projected_x = tuple(projected_dimension_names) | ||
if len(projected_dimension_names) >= 2: | ||
D-Auty marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
projected_y, projected_x = ( | ||
projected_dimension_names[-2], | ||
projected_dimension_names[-1], | ||
) | ||
joeyschultz marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
if dim_order_is_y_x: | ||
return {projected_y: y_dim, projected_x: x_dim} | ||
raise UnsupportedDimensionOrder('x,y') | ||
# this is not currently supported in the calling function in spatial.py | ||
# return {projected_x: x_dim, projected_y: y_dim} | ||
|
||
if dim_order_is_y_x: | ||
return {projected_y: y_dim, projected_x: x_dim} | ||
raise UnsupportedDimensionOrder('x,y') | ||
# this is not currently supported in the calling function in spatial.py | ||
# return {projected_x: x_dim, projected_y: y_dim} | ||
raise UnsupportedDimensionOrder(projected_dimension_names) | ||
joeyschultz marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
|
||
def get_2d_coordinate_array( | ||
|
@@ -322,8 +347,16 @@ def get_dimension_order_and_dim_values( | |
projected spatial dimension. The input lat lon arrays and dimension | ||
indices are assumed to be 2D in this implementation of the function. | ||
""" | ||
lat_arr_values = [lat_array_points[i][j] for i, j in grid_dimension_indices] | ||
lon_arr_values = [lon_array_points[i][j] for i, j in grid_dimension_indices] | ||
if lat_array_points.ndim == 1 and lon_array_points.ndim == 1: | ||
lat_arr_values = lat_array_points | ||
lon_arr_values = lon_array_points | ||
elif lat_array_points.ndim == 2 and lon_array_points.ndim == 2: | ||
lat_arr_values = [lat_array_points[i][j] for i, j in grid_dimension_indices] | ||
lon_arr_values = [lon_array_points[i][j] for i, j in grid_dimension_indices] | ||
else: | ||
# assuming a nominal z,y,x order | ||
D-Auty marked this conversation as resolved.
Show resolved
Hide resolved
|
||
lat_arr_values = [lat_array_points[0][i][j] for i, j in grid_dimension_indices] | ||
lon_arr_values = [lon_array_points[0][i][j] for i, j in grid_dimension_indices] | ||
|
||
from_geo_transformer = Transformer.from_crs(4326, crs) | ||
x_values, y_values = ( # pylint: disable=unpacking-non-sequence | ||
|
Uh oh!
There was an error while loading. Please reload this page.