Skip to content
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

Change x,y,z, to lat,lon,levelist in timeseries #60

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
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
23 changes: 15 additions & 8 deletions covjsonkit/decoder/TimeSeries.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ def get_coordinates(self):
coord_dict[param] = []
# Get x,y,z,t coords and unpack t coords and match to x,y,z coords
for ind, domain in enumerate(self.domains):
x = domain["axes"]["x"]["values"][0]
y = domain["axes"]["y"]["values"][0]
z = domain["axes"]["z"]["values"][0]
x = domain["axes"]["latitude"]["values"][0]
y = domain["axes"]["longitude"]["values"][0]
z = domain["axes"]["levelist"]["values"][0]
fct = domain["axes"]["t"]["values"][0]
ts = domain["axes"]["t"]["values"]
if "number" in self.mars_metadata[ind]:
Expand All @@ -59,14 +59,14 @@ def to_geopandas(self):

# function to convert covjson to xarray dataset
def to_xarray(self):
dims = ["x", "y", "z", "number", "datetime", "t"]
dims = ["latitude", "longitude", "levelist", "number", "datetime", "t"]
dataarraydict = {}

# Get coordinates
coords = self.get_domains()
x = coords[0]["axes"]["x"]["values"]
y = coords[0]["axes"]["y"]["values"]
z = coords[0]["axes"]["z"]["values"]
x = coords[0]["axes"]["latitude"]["values"]
y = coords[0]["axes"]["longitude"]["values"]
z = coords[0]["axes"]["levelist"]["values"]
steps = coords[0]["axes"]["t"]["values"]
steps = [step.replace("Z", "") for step in steps]
steps = pd.to_datetime(steps)
Expand Down Expand Up @@ -98,7 +98,14 @@ def to_xarray(self):
param_values[parameter][i][j] = coverage["ranges"][parameter]["values"]

for parameter in self.parameters:
param_coords = {"x": x, "y": y, "z": z, "number": nums, "datetime": datetime, "t": steps}
param_coords = {
"latitude": x,
"longitude": y,
"levelist": z,
"number": nums,
"datetime": datetime,
"t": steps,
}
dataarray = xr.DataArray(
[[[param_values[parameter]]]],
dims=dims,
Expand Down
20 changes: 10 additions & 10 deletions covjsonkit/encoder/TimeSeries.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ def add_coverage(self, mars_metadata, coords, values):
def add_domain(self, coverage, coords):
coverage["domain"]["type"] = "Domain"
coverage["domain"]["axes"] = {}
coverage["domain"]["axes"]["x"] = {}
coverage["domain"]["axes"]["y"] = {}
coverage["domain"]["axes"]["z"] = {}
coverage["domain"]["axes"]["latitude"] = {}
coverage["domain"]["axes"]["longitude"] = {}
coverage["domain"]["axes"]["levelist"] = {}
coverage["domain"]["axes"]["t"] = {}
coverage["domain"]["axes"]["x"]["values"] = coords["x"]
coverage["domain"]["axes"]["y"]["values"] = coords["y"]
coverage["domain"]["axes"]["z"]["values"] = coords["z"]
coverage["domain"]["axes"]["latitude"]["values"] = coords["latitude"]
coverage["domain"]["axes"]["longitude"]["values"] = coords["longitude"]
coverage["domain"]["axes"]["levelist"]["values"] = coords["levelist"]
coverage["domain"]["axes"]["t"]["values"] = coords["t"]

def add_range(self, coverage, values):
Expand Down Expand Up @@ -111,7 +111,7 @@ def from_polytope(self, result):

self.add_reference(
{
"coordinates": ["x", "y", "z"],
"coordinates": ["latitude", "longitude", "levelist"],
"system": {
"type": "GeographicCRS",
"id": "http://www.opengis.net/def/crs/OGC/1.3/CRS84",
Expand All @@ -131,9 +131,9 @@ def from_polytope(self, result):

for date in fields["dates"]:
coordinates[date] = {
"x": [coords[date]["composite"][0][0]],
"y": [coords[date]["composite"][0][1]],
"z": [levels[0]],
"latitude": [coords[date]["composite"][0][0]],
"longitude": [coords[date]["composite"][0][1]],
"levelist": [levels[0]],
}
coordinates[date]["t"] = []
for level in fields["levels"]:
Expand Down
Loading