Coder Social home page Coder Social logo

Design for CRS extension about geoxarray HOT 10 CLOSED

geoxarray avatar geoxarray commented on June 2, 2024 1
Design for CRS extension

from geoxarray.

Comments (10)

djhoese avatar djhoese commented on June 2, 2024 1

@atedstone FYI #13

from geoxarray.

djhoese avatar djhoese commented on June 2, 2024

A couple questions/clarifications if you could:

  1. Is there any reason that geo.crs has to be set or should crs_from_cf allow users to provide the CF grid mapping information to create the CRS with the default (no arguments) being to look at the current Dataset/DataArray for expected attributes?

  2. This could only be done for Datasets right?

My understanding was that geoxarray would be providing utilities for creating the crs coordinate and adding additional "standard" attributes (CF, etc) from an existing crs coordinate. Let me know if this isn't what you were thinking.

from geoxarray.

snowman2 avatar snowman2 commented on June 2, 2024

Is there any reason that geo.crs has to be set or should crs_from_cf allow users to provide the CF grid mapping information to create the CRS with the default (no arguments) being to look at the current Dataset/DataArray for expected attributes?

Ideally, it would be best for the CRS to be pulled from the current Dataset/DataArray expected attributes. However, there are so many different ways that this data is stored that it is likely going to fail if it is on a non-standard location or format. With this line of thinking, it would be nice to have multiple methods for setting the CRS as a backup. For example, if you already have a pyproj.CRS or rasterio.CRS generated using an alternate method, it would be nice to be able to:

geo.crs = CRS("epsg:4326")

I guess you could do:

geo.crs_from_cf(crs_wkt=CRS("epsg:4326").to_wkt())

But, it is not as clean IMO.

This could only be done for Datasets right?

This can work for both data arrays and datasets. If it is a data array, then it is much simpler as you only have one location to search for the CRS. Whereas if it is a dataset, then some logic needs to be added to determine which CRS is used by which variable if there are more then one (or just assume that there is only one CRS for the entire dataset).

My understanding was that geoxarray would be providing utilities for creating the crs coordinate and adding additional "standard" attributes (CF, etc) from an existing crs coordinate. Let me know if this isn't what you were thinking.

Yes, this is what I am thinking is the end goal. But, until it is ready in geoxarray, I was thinking about adding it in to rioxarray as a temporary addition that can be replaced at a later date.

from geoxarray.

djhoese avatar djhoese commented on June 2, 2024

So is data_arr.geo.crs = CRS(...) kind of a magic "take this CRS information and add it to my Dataarray whether it be a dictionary (of CF attributes), a rasterio CRS object, or a pyproj CRS object, or something else?

Looking at the spatial_ref stuff I think I get it a little better now. It is being added as a coordinate variable and not as another variable in a Dataset.

from geoxarray.

snowman2 avatar snowman2 commented on June 2, 2024

So is data_arr.geo.crs = CRS(...) kind of a magic "take this CRS information and add it to my Dataarray whether it be a dictionary (of CF attributes), a rasterio CRS object, or a pyproj CRS object, or something else?

That is the general idea. I am not sure about the CF dict as there can also be PROJ dicts. So, you would need a way to differentiate. Maybe look for proj or init for PROJ string versus grid_mapping_name, crs_wkt or spatial_ref for CF dict.

from geoxarray.

djhoese avatar djhoese commented on June 2, 2024

I'd say that wouldn't be a bad idea if the property is already magic-ish.

from geoxarray.

snowman2 avatar snowman2 commented on June 2, 2024

Okay, sounds good to me 👍

from geoxarray.

atedstone avatar atedstone commented on June 2, 2024

Hi. I'd been poised a couple of days ago to generalise some of my existing code from a couple of years ago for writing CF-compliant netcdfs using xarray, but some searching revealed this project. I can give some time to helping with getting and setting CRS info on xarray Datasets, especially in creating functionality to write CF-compliant netCDFs. Before I start anything though, is there any local development of the CRS extension happening at the moment that hasn't made it to Github?

from geoxarray.

djhoese avatar djhoese commented on June 2, 2024

Yes! I was just about to push the changes even though I wasn't happy with everything. I'd also check out @snowman2's progress on rioxarray.

from geoxarray.

djhoese avatar djhoese commented on June 2, 2024

Closing this as the initial support in #26 is merged and mimics rioxarray's support. That is, .geo.crs gives you a pyproj CRS object. .geo.write_crs writes a CF-compatible grid_mapping variable to the .coords of the current xarray object. Due to difficulties persisting information in an xarray accessor there is no way to provide the geoxarray accessor CRS information without persisting it with .geo.write_crs. Put another way, it is too easily to accidentally lose the temporary/internal CRS information if it isn't persisted in the xarray object itself.

from geoxarray.

Related Issues (18)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.