Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
## v1.1.6
### 2025-02-24

This version of HOSS adds support for multiple coordinate variables that
are in the same group for cases where coordinates are used in place of
dimensions. This also supports exclusive requests of coordinate
datasets that do not have coordinate attributes or dimensions.

## v1.1.5
### 2025-02-14

Expand Down
2 changes: 1 addition & 1 deletion docker/service_version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.1.5
1.1.6
43 changes: 22 additions & 21 deletions hoss/coordinate_utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,42 +106,37 @@ def get_dimension_array_names(
latitude_coordinates, longitude_coordinates = get_coordinate_variables(
varinfo, [variable_name]
)
# Given variable has coordinates: use latitude coordinate
# Given variable has coordinates: use latitude and longitude coordinate
# to define variable spatial dimensions.
if len(latitude_coordinates) == 1 and len(longitude_coordinates) == 1:
dimension_names = create_spatial_dimension_names_from_coordinates(
varinfo, latitude_coordinates[0]
)

# Given variable variable has no coordinate attribute itself,
# but is itself a coordinate (latitude or longitude):
# use as a coordinate to define spatial dimensions
elif variable.is_latitude() or variable.is_longitude():
dimension_names = create_spatial_dimension_names_from_coordinates(
varinfo, variable_name
varinfo, latitude_coordinates[0], longitude_coordinates[0]
)
else:
dimension_names = {}
return dimension_names


def create_spatial_dimension_names_from_coordinates(
varinfo: VarInfoFromDmr, variable_name: str
varinfo: VarInfoFromDmr, lat_coord_name: str, lon_coord_name: str
) -> dict[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
"""returns the x-y dimension names concatenated with full path names
of the latitude and longitude coordinate variable names. The names are
returned as a dictionary with y_coordinate, x_coordinate order.

"""
variable = varinfo.get_variable(variable_name)
lat_coord_variable = varinfo.get_variable(lat_coord_name)
lon_coord_variable = varinfo.get_variable(lon_coord_name)

if variable is not None:
if lat_coord_variable is not None and lon_coord_variable is not None:
dimension_names = {
'projection_y_coordinate': f'{variable.group_path}/y_dim',
'projection_x_coordinate': f'{variable.group_path}/x_dim',
'projection_y_coordinate': f'{lat_coord_variable.full_name_path}_'
f'{lon_coord_variable.full_name_path}/y_dim',
'projection_x_coordinate': f'{lat_coord_variable.full_name_path}_'
f'{lon_coord_variable.full_name_path}/x_dim',
}
else:
raise MissingVariable(variable_name)
raise MissingVariable(f'{lat_coord_name},{lon_coord_name}')
return dimension_names


Expand All @@ -159,7 +154,6 @@ def create_dimension_arrays_from_coordinates(
3) Generate the x-y dimscale array and return to the calling method

"""
# dimension_names = get_dimension_array_names(varinfo, variable_name)
if len(dimension_names) < 2:
raise InvalidDimensionNames(dimension_names)

Expand Down Expand Up @@ -263,10 +257,17 @@ def get_valid_sample_pts(

# get maximally spread points within rows
max_x_spread_pts = get_max_spread_pts(~valid_lat_lon_mask)
if valid_lat_lon_mask.ndim == 2:
transpose_mask = np.transpose(~valid_lat_lon_mask)
elif valid_lat_lon_mask.ndim == 3:
# this is for nominal order (z,y,x)
transpose_mask = np.transpose(~valid_lat_lon_mask, (0, 2, 1))
else:
raise NotImplementedError

# Doing the same for the columns is done by transposing the valid_mask
# and then fixing the results from [x, y] to [y, x].
max_y_spread_trsp = get_max_spread_pts(np.transpose(~valid_lat_lon_mask))
max_y_spread_trsp = get_max_spread_pts(transpose_mask)
max_y_spread_pts = [
list(np.flip(max_y_spread_trsp[0])),
list(np.flip(max_y_spread_trsp[1])),
Expand Down
152 changes: 148 additions & 4 deletions hoss/hoss_config.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"Identification": "hoss_config",
"Version": 22,
"Version": 23,
"CollectionShortNamePath": [
"/HDF5_GLOBAL/short_name",
"/NC_GLOBAL/short_name",
Expand Down Expand Up @@ -400,6 +400,132 @@
],
"_Description": "Ensure variables in /Soil_Moisture_Retrieval_Data_Polar_PM group point to correct coordinate variables."
},
{
"Applicability": {
"Mission": "SMAP",
"ShortNamePath": "SPL3SMP",
"VariablePattern": "/Soil_Moisture_Retrieval_Data_AM/(lat|long)itude"
},
"Attributes": [
{
"Name": "coordinates",
"Value": "/Soil_Moisture_Retrieval_Data_AM/latitude, /Soil_Moisture_Retrieval_Data_AM/longitude"
}
],
"_Description": "Ensure coordinate variables in /Soil_Moisture_Retrieval_Data_AM group have coordinate attributes."
},
{
"Applicability": {
"Mission": "SMAP",
"ShortNamePath": "SPL3SMP_E",
"VariablePattern": "/Soil_Moisture_Retrieval_Data_AM/(lat|long)itude"
},
"Attributes": [
{
"Name": "coordinates",
"Value": "/Soil_Moisture_Retrieval_Data_AM/latitude, /Soil_Moisture_Retrieval_Data_AM/longitude"
}
],
"_Description": "Ensure coordinate variables in /Soil_Moisture_Retrieval_Data_AM group have coordinate attributes."
},
{
"Applicability": {
"Mission": "SMAP",
"ShortNamePath": "SPL3SMP_E",
"VariablePattern": "/Soil_Moisture_Retrieval_Data_Polar_AM/(lat|long)itude"
},
"Attributes": [
{
"Name": "coordinates",
"Value": "/Soil_Moisture_Retrieval_Data_Polar_AM/latitude, /Soil_Moisture_Retrieval_Data_Polar_AM/longitude"
}
],
"_Description": "Ensure coordinate variables in /Soil_Moisture_Retrieval_Data_Polar_AM group have coordinate attributes."
},
{
"Applicability": {
"Mission": "SMAP",
"ShortNamePath": "SPL3SM(A|AP)",
"VariablePattern": "/Soil_Moisture_Retrieval_Data/(lat|long)itude"
},
"Attributes": [
{
"Name": "coordinates",
"Value": "/Soil_Moisture_Retrieval_Data/latitude, /Soil_Moisture_Retrieval_Data/longitude"
}
],
"_Description": "Ensure coordinate variables in /Soil_Moisture_Retrieval_Data group have coordinate attributes."
},
{
"Applicability": {
"Mission": "SMAP",
"ShortNamePath": "SPL2SMAP_S",
"VariablePattern": "/Soil_Moisture_Retrieval_Data_1km/(lat|long)itude_1km"
},
"Attributes": [
{
"Name": "coordinates",
"Value": "/Soil_Moisture_Retrieval_Data_1km/latitude_1km, /Soil_Moisture_Retrieval_Data_1km/longitude_1km"
}
],
"_Description": "Ensure coordinate variables in /Soil_Moisture_Retrieval_Data_1km group have coordinate attributes."
},
{
"Applicability": {
"Mission": "SMAP",
"ShortNamePath": "SPL2SMAP_S",
"VariablePattern": "/Soil_Moisture_Retrieval_Data_3km/(lat|long)itude_3km"
},
"Attributes": [
{
"Name": "coordinates",
"Value": "/Soil_Moisture_Retrieval_Data_3km/latitude_3km, /Soil_Moisture_Retrieval_Data_3km/longitude_3km"
}
],
"_Description": "Ensure coordinate variables in /Soil_Moisture_Retrieval_Data_3km group have coordinate attributes."
},
{
"Applicability": {
"Mission": "SMAP",
"ShortNamePath": "SPL3FTA",
"VariablePattern": "/Freeze_Thaw_Retrieval_Data/(lat|long)itude"
},
"Attributes": [
{
"Name": "coordinates",
"Value": "/Freeze_Thaw_Retrieval_Data/latitude, /Freeze_Thaw_Retrieval_Data/longitude"
}
],
"_Description": "Ensure coordinate variables in /Freeze_Thaw_Retrieval_Data group have coordinate attributes."
},
{
"Applicability": {
"Mission": "SMAP",
"ShortNamePath": "SPL3FT(P|P_E)",
"VariablePattern": "/Freeze_Thaw_Retrieval_Data_Global/(lat|long)itude"
},
"Attributes": [
{
"Name": "coordinates",
"Value": "/Freeze_Thaw_Retrieval_Data_Global/latitude, /Freeze_Thaw_Retrieval_Data_Global/longitude"
}
],
"_Description": "Ensure coordinate variables in /Freeze_Thaw_Retrieval_Data_Global group have coordinate attributes."
},
{
"Applicability": {
"Mission": "SMAP",
"ShortNamePath": "SPL3FT(P|P_E)",
"VariablePattern": "/Freeze_Thaw_Retrieval_Data_Polar/(latitude|longitude)"
},
"Attributes": [
{
"Name": "coordinates",
"Value": "/Freeze_Thaw_Retrieval_Data_Polar/latitude, /Freeze_Thaw_Retrieval_Data_Polar/longitude"
}
],
"_Description": "Ensure coordinate variables in /Freeze_Thaw_Retrieval_Data_Polar group have coordinate attributes."
},
{
"Applicability": {
"Mission": "SMAP",
Expand Down Expand Up @@ -445,7 +571,7 @@
{
"Applicability": {
"Mission": "SMAP",
"ShortNamePath": "SPL3SMP",
"ShortNamePath": "SPL3SMP|SPL3FT(A|P|P_E)",
"VariablePattern": ".*/x_dim"
},
"Attributes": [
Expand All @@ -467,7 +593,7 @@
{
"Applicability": {
"Mission": "SMAP",
"ShortNamePath": "SPL3SMP",
"ShortNamePath": "SPL3SMP|SPL3FT(A|P|P_E)",
"VariablePattern": ".*/y_dim"
},
"Attributes": [
Expand All @@ -489,7 +615,7 @@
{
"Applicability": {
"Mission": "SMAP",
"ShortNamePath": "SPL3SMP",
"ShortNamePath": "SPL3FT(A|P|P_E)",
"VariablePattern": ".*/am_pm"
},
"Attributes": [
Expand All @@ -504,6 +630,24 @@
],
"_Description": "The pseudo-dimension variable is here supplemented with variable attributes (as if it was a dimension variables) to clarify the dimension name"
},
{
"Applicability": {
"Mission": "SMAP",
"ShortNamePath": "SPL3SMP",
"VariablePattern": ".*/lc_type"
},
"Attributes": [
{
"Name": "dimensions",
"Value": "lc_type"
},
{
"Name": "long_name",
"Value": "land cover type"
}
],
"_Description": "The pseudo-dimension variable is here supplemented with variable attributes (as if it was a dimension variable) to clarify the dimension name"
},
{
"Applicability": {
"Mission": "ICESat2",
Expand Down
3 changes: 1 addition & 2 deletions hoss/projection_utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,7 @@ def get_grid_mapping_attributes(variable: str, varinfo: VarInfoFromDmr) -> Dict:

if cf_attributes:
return cf_attributes
else:
raise MissingGridMappingVariable(grid_mapping, variable)
raise MissingGridMappingVariable(grid_mapping, variable)

except AttributeError as exception:
raise MissingGridMappingVariable(grid_mapping, variable) from exception
Expand Down
84 changes: 84 additions & 0 deletions tests/data/SC_SPL3SMP_008_fake.dmr
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,90 @@
<Value>Y</Value>
</Attribute>
</Float64>
<Float32 name="same_folder_longitude1">
<Dim size="406"/>
<Dim size="964"/>
<Attribute name="long_name" type="String">
<Value>Longitude of the center of the Earth based grid cell.</Value>
</Attribute>
<Attribute name="units" type="String">
<Value>degrees_east</Value>
</Attribute>
</Float32>
<Float32 name="same_folder_latitude1">
<Dim size="406"/>
<Dim size="964"/>
<Attribute name="long_name" type="String">
<Value>Latitude of the center of the Earth based grid cell.</Value>
</Attribute>
<Attribute name="units" type="String">
<Value>degrees_north</Value>
</Attribute>
</Float32>
<Float32 name="same_folder_longitude2">
<Dim size="406"/>
<Dim size="964"/>
<Attribute name="long_name" type="String">
<Value>Longitude of the center of the Earth based grid cell.</Value>
</Attribute>
<Attribute name="units" type="String">
<Value>degrees_east</Value>
</Attribute>
</Float32>
<Float32 name="same_folder_latitude2">
<Dim size="406"/>
<Dim size="964"/>
<Attribute name="long_name" type="String">
<Value>Latitude of the center of the Earth based grid cell.</Value>
</Attribute>
<Attribute name="units" type="String">
<Value>degrees_north</Value>
</Attribute>
</Float32>
<Float32 name ="variable1_with_same_folder_coordinates">
<Dim size="406"/>
<Dim size="964"/>
<Attribute name="long_name" type="String">
<Value>Representative SCA-V soil moisture measurement for the Earth based grid cell.</Value>
</Attribute>
<Attribute name="units" type="String">
<Value>cm**3/cm**3</Value>
</Attribute>
<Attribute name="coordinates" type="String">
<Value>/Soil_Moisture_Retrieval_Data_AM/same_folder_latitude1 /Soil_Moisture_Retrieval_Data_AM/same_folder_longitude1</Value>
</Attribute>
<Attribute name="valid_min" type="Float32">
<Value>0.01999999955</Value>
</Attribute>
<Attribute name="valid_max" type="Float32">
<Value>0.5</Value>
</Attribute>
<Attribute name="_FillValue" type="Float32">
<Value>-9999.</Value>
</Attribute>
</Float32>
<Float32 name ="variable2_with_same_folder_coordinates">
<Dim size="406"/>
<Dim size="964"/>
<Attribute name="long_name" type="String">
<Value>Representative SCA-V soil moisture measurement for the Earth based grid cell.</Value>
</Attribute>
<Attribute name="units" type="String">
<Value>cm**3/cm**3</Value>
</Attribute>
<Attribute name="coordinates" type="String">
<Value>/Soil_Moisture_Retrieval_Data_AM/same_folder_latitude2 /Soil_Moisture_Retrieval_Data_AM/same_folder_longitude2</Value>
</Attribute>
<Attribute name="valid_min" type="Float32">
<Value>0.01999999955</Value>
</Attribute>
<Attribute name="valid_max" type="Float32">
<Value>0.5</Value>
</Attribute>
<Attribute name="_FillValue" type="Float32">
<Value>-9999.</Value>
</Attribute>
</Float32>
<Byte name="landcover_class">
<Dim size="406"/>
<Dim size="964"/>
Expand Down
Loading