Skip to content

Commit

Permalink
Update readme, fix frame, wkt and shapefile for level
Browse files Browse the repository at this point in the history
  • Loading branch information
awarde96 committed Aug 28, 2024
1 parent 9f4196c commit df4f31d
Show file tree
Hide file tree
Showing 5 changed files with 129 additions and 21 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,13 @@ The example config has to be stored in one of the following places:

Users can add their own parameter metadata in the [data directory](covjsonkit/data/) by add ing a new directory containing a param.json, param_id.json, and units.json in a format the same as can be found in [ecmwf directory](covjsonkit/data/ecmwf/). Then edit the config to point to your newly named directory.

If users want to pass in their own config tehy can do this as a python dictioanry in the following way:

```Python
encoder = Covjsonkit(cf).encode("CoverageCollection", "BoundingBox")
```

Where `cf` is a valid covjsonkit config.
## Testing

Python unit tests can be run with pytest:
Expand Down
47 changes: 40 additions & 7 deletions covjsonkit/encoder/Frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,16 +81,16 @@ def from_xarray(self, dataset):
def from_polytope(self, result):

coords = {}
# coords['composite'] = []
mars_metadata = {}
range_dict = {}
lat = 0
param = 0
number = [0]
step = 0
dates = [0]
levels = [0]

self.walk_tree(result, lat, coords, mars_metadata, param, range_dict, number, step, dates)
self.walk_tree(result, lat, coords, mars_metadata, param, range_dict, number, step, dates, levels)

self.add_reference(
{
Expand All @@ -102,18 +102,51 @@ def from_polytope(self, result):
}
)

combined_dict = {}

for date in range_dict:
if date not in combined_dict:
combined_dict[date] = {}
for level in range_dict[date]:
for num in range_dict[date][level]:
if num not in combined_dict[date]:
combined_dict[date][num] = {}
for para in range_dict[date][level][num]:
if para not in combined_dict[date][num]:
combined_dict[date][num][para] = {}
for s, value in range_dict[date][level][num][para].items():
if s not in combined_dict[date][num][para]:
combined_dict[date][num][para][s] = value
else:
# Cocatenate arrays
combined_dict[date][num][para][s] += value

levels = []
for date in range_dict.keys():
for num in range_dict[date].keys():
for level in range_dict[date].keys():
levels.append(level)
break

for date in coords.keys():
coord = coords[date]["composite"]
coords[date]["composite"] = []
for level in levels:
for cor in coord:
coords[date]["composite"].append([cor[0], cor[1], level])

for date in combined_dict.keys():
for num in combined_dict[date].keys():
val_dict = {}
for step in range_dict[date][num][self.parameters[0]].keys():
for step in combined_dict[date][num][self.parameters[0]].keys():
val_dict[step] = {}
for para in range_dict[date][num].keys():
for step in range_dict[date][num][para].keys():
val_dict[step][para] = range_dict[date][num][para][step]
for para in combined_dict[date][num].keys():
for step in combined_dict[date][num][para].keys():
val_dict[step][para] = combined_dict[date][num][para][step]
for step in val_dict.keys():
mm = mars_metadata.copy()
mm["number"] = num
mm["step"] = step
mm["Forecast date"] = date
self.add_coverage(mm, coords[date], val_dict[step])

# self.add_coverage(mars_metadata, coords, range_dict)
Expand Down
47 changes: 40 additions & 7 deletions covjsonkit/encoder/Shapefile.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,16 +81,16 @@ def from_xarray(self, dataset):
def from_polytope(self, result):

coords = {}
# coords['composite'] = []
mars_metadata = {}
range_dict = {}
lat = 0
param = 0
number = [0]
step = 0
dates = [0]
levels = [0]

self.walk_tree(result, lat, coords, mars_metadata, param, range_dict, number, step, dates)
self.walk_tree(result, lat, coords, mars_metadata, param, range_dict, number, step, dates, levels)

self.add_reference(
{
Expand All @@ -102,18 +102,51 @@ def from_polytope(self, result):
}
)

combined_dict = {}

for date in range_dict:
if date not in combined_dict:
combined_dict[date] = {}
for level in range_dict[date]:
for num in range_dict[date][level]:
if num not in combined_dict[date]:
combined_dict[date][num] = {}
for para in range_dict[date][level][num]:
if para not in combined_dict[date][num]:
combined_dict[date][num][para] = {}
for s, value in range_dict[date][level][num][para].items():
if s not in combined_dict[date][num][para]:
combined_dict[date][num][para][s] = value
else:
# Cocatenate arrays
combined_dict[date][num][para][s] += value

levels = []
for date in range_dict.keys():
for num in range_dict[date].keys():
for level in range_dict[date].keys():
levels.append(level)
break

for date in coords.keys():
coord = coords[date]["composite"]
coords[date]["composite"] = []
for level in levels:
for cor in coord:
coords[date]["composite"].append([cor[0], cor[1], level])

for date in combined_dict.keys():
for num in combined_dict[date].keys():
val_dict = {}
for step in range_dict[date][num][self.parameters[0]].keys():
for step in combined_dict[date][num][self.parameters[0]].keys():
val_dict[step] = {}
for para in range_dict[date][num].keys():
for step in range_dict[date][num][para].keys():
val_dict[step][para] = range_dict[date][num][para][step]
for para in combined_dict[date][num].keys():
for step in combined_dict[date][num][para].keys():
val_dict[step][para] = combined_dict[date][num][para][step]
for step in val_dict.keys():
mm = mars_metadata.copy()
mm["number"] = num
mm["step"] = step
mm["Forecast date"] = date
self.add_coverage(mm, coords[date], val_dict[step])

# self.add_coverage(mars_metadata, coords, range_dict)
Expand Down
47 changes: 40 additions & 7 deletions covjsonkit/encoder/Wkt.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,16 +81,16 @@ def from_xarray(self, dataset):
def from_polytope(self, result):

coords = {}
# coords['composite'] = []
mars_metadata = {}
range_dict = {}
lat = 0
param = 0
number = [0]
step = 0
dates = [0]
levels = [0]

self.walk_tree(result, lat, coords, mars_metadata, param, range_dict, number, step, dates)
self.walk_tree(result, lat, coords, mars_metadata, param, range_dict, number, step, dates, levels)

self.add_reference(
{
Expand All @@ -102,18 +102,51 @@ def from_polytope(self, result):
}
)

combined_dict = {}

for date in range_dict:
if date not in combined_dict:
combined_dict[date] = {}
for level in range_dict[date]:
for num in range_dict[date][level]:
if num not in combined_dict[date]:
combined_dict[date][num] = {}
for para in range_dict[date][level][num]:
if para not in combined_dict[date][num]:
combined_dict[date][num][para] = {}
for s, value in range_dict[date][level][num][para].items():
if s not in combined_dict[date][num][para]:
combined_dict[date][num][para][s] = value
else:
# Cocatenate arrays
combined_dict[date][num][para][s] += value

levels = []
for date in range_dict.keys():
for num in range_dict[date].keys():
for level in range_dict[date].keys():
levels.append(level)
break

for date in coords.keys():
coord = coords[date]["composite"]
coords[date]["composite"] = []
for level in levels:
for cor in coord:
coords[date]["composite"].append([cor[0], cor[1], level])

for date in combined_dict.keys():
for num in combined_dict[date].keys():
val_dict = {}
for step in range_dict[date][num][self.parameters[0]].keys():
for step in combined_dict[date][num][self.parameters[0]].keys():
val_dict[step] = {}
for para in range_dict[date][num].keys():
for step in range_dict[date][num][para].keys():
val_dict[step][para] = range_dict[date][num][para][step]
for para in combined_dict[date][num].keys():
for step in combined_dict[date][num][para].keys():
val_dict[step][para] = combined_dict[date][num][para][step]
for step in val_dict.keys():
mm = mars_metadata.copy()
mm["number"] = num
mm["step"] = step
mm["Forecast date"] = date
self.add_coverage(mm, coords[date], val_dict[step])

# self.add_coverage(mars_metadata, coords, range_dict)
Expand Down
2 changes: 2 additions & 0 deletions covjsonkit/encoder/encoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@ def walk_tree(self, tree, lat, coords, mars_metadata, param, range_dict, number,
number = c.values
for date in dates:
for level in levels:
if level not in range_dict[date]:
range_dict[date][level] = {}
for num in number:
range_dict[date][level][num] = {}
if c.axis.name == "step":
Expand Down

0 comments on commit df4f31d

Please sign in to comment.