logo
Tags down

shadow

reassigning xarray data variable to xarray coordinate


By : Helen
Date : September 14 2020, 04:00 PM
fixed the issue. Will look into that further I have a pandas dataframe of spatial data that I would like to convert to a netCDF. I have found my way to xarray and converted my dataframe into an xarray dataset: , Starting from a Dataset called ds that looks like this:
code :
Dimensions:  (index: 10)
Coordinates:
  * index    (index) int64 0 1 2 3 4 5 6 7 8 9
Data variables:
    dv_v     (index) int64 5 14 6 1 19 12 16 10 0 11
    rxy      (index) int64 15 8 6 2 0 1 4 16 7 19
    lon      (index) int64 15 7 9 17 18 1 12 2 6 8
    lat      (index) int64 6 8 5 17 15 16 9 19 11 14
    rxyz     (index) int64 15 17 18 5 14 13 16 2 10 9
    depth    (index) int64 11 18 5 19 3 14 7 17 0 4
Dimensions:  (index: 10)
Coordinates:
  * index    (index) int64 0 1 2 3 4 5 6 7 8 9
    lon      (index) int64 15 7 9 17 18 1 12 2 6 8
    lat      (index) int64 6 8 5 17 15 16 9 19 11 14
Data variables:
    dv_v     (index) int64 5 14 6 1 19 12 16 10 0 11
    rxy      (index) int64 15 8 6 2 0 1 4 16 7 19
    rxyz     (index) int64 15 17 18 5 14 13 16 2 10 9
    depth    (index) int64 11 18 5 19 3 14 7 17 0 4
Dimensions:  (index: 10)
Coordinates:
  * index    (index) MultiIndex
  - lat      (index) int64 6 8 5 17 15 16 9 19 11 14
  - lon      (index) int64 15 7 9 17 18 1 12 2 6 8
Data variables:
    dv_v     (index) int64 5 14 6 1 19 12 16 10 0 11
    rxy      (index) int64 15 8 6 2 0 1 4 16 7 19
    rxyz     (index) int64 15 17 18 5 14 13 16 2 10 9
    depth    (index) int64 11 18 5 19 3 14 7 17 0 4


Share : facebook icon twitter icon

Python xarray.concat then xarray.to_netcdf generates huge new file size


By : PBo
Date : March 29 2020, 07:55 AM
I wish this helpful for you The netCDF files you started with are compressed, probably using netCDF4's chunk-wise compression feature.
When you read a single dataset and write it back to disk, xarray writes that data back with the same compression settings. But when you combine multiple files, the compression settings are reset. Part of the reason for this is that different file may be compressed on disk in different ways, so it isn't obvious how the combined result should be handled.
code :
ds_new.to_netcdf('saved_on_disk1.nc', encoding={'dis': {'zlib': True}})

Join along a non-coordinate dimension in xarray


By : Jorge Ramirez Zamora
Date : March 29 2020, 07:55 AM
I think the issue was by ths following , I'm trying to join a set of values from one DataArray, to another. They should join based on a non-dimension coordinate of the first. I think this should be easy but I can't seem to work it out. , You need to groupby the first but not apply an aggregation to it:
code :
In [6]: primary.groupby('group') - secondary
Out[6]: 
<xarray.DataArray (a: 4)>
array([-0.48171525, -0.69818249, -0.38572403, -0.54330502])
Coordinates:
  * a        (a) int64 0 1 2 3
    group    (a) int64 0 0 1 1

python-xarray: how to convert individual-band raster data, for multiple bands and dates, to xarray-Dataset or DataArray?


By : Fan
Date : March 29 2020, 07:55 AM
seems to work fine As mentioned by jhamman, a lot depends on where you data comes from to determine how to combine it. This is one way of combining the data you've posed, but there are other approaches.
There are multiple steps needed to combine this data. First, name each of the DataArrays, with the name of the variable you want it to end up in.
code :
d1_b4.name = 'band4'
d1_b5.name = 'band5'
d2_b4.name = 'band4'
d2_b5.name = 'band5'
d1 = xr.merge([d1_b4, d1_b5])
d2 = xr.merge([d2_b4, d2_b5])

<xarray.Dataset>
Dimensions:  (x: 3, y: 3)
Coordinates:
  * x        (x) <U1 '1' '2' '3'
  * y        (y) <U1 'a' 'b' 'c'
Data variables:
    band4    (x, y) int64 241 242 243 244 245 246 247 248 249
    band5    (x, y) int64 251 252 253 254 255 256 257 258 259
xr.concat([d1, d2], dim=pd.Index([1990, 1991], name='time'))

<xarray.Dataset>
Dimensions:  (time: 2, x: 3, y: 3)
Coordinates:
  * x        (x) <U1 '1' '2' '3'
  * y        (y) <U1 'a' 'b' 'c'
  * time     (time) int64 1990 1991
Data variables:
    band4    (time, x, y) int64 141 142 143 144 145 146 147 148 149 241 242 ...
    band5    (time, x, y) int64 151 152 153 154 155 156 157 158 159 251 252 ...

Change coordinate in xarray dataset


By : user1489275
Date : March 29 2020, 07:55 AM
this will help Xarray's Dataset object has a built-in method to do exactly this: Dataset.swap_dims. The documentation is here: http://xarray.pydata.org/en/stable/generated/xarray.Dataset.swap_dims.html
In your case, with ds as your Dataset,
code :
ds.swap_dims({'x': 'y'}, inplace=True)
ds_new = ds.swap_dims({'x', 'y'})

Dropping dimension without coordinate using xarray


By : LE MEE
Date : March 29 2020, 07:55 AM
I wish did fix the issue. not clear what you want to do: dataarr.drop('N') will remove only coordinate ; mostly useful for redundant coordinate.
but your data's equivalent numpy dimensions would still be array of shape (20,360,720,3) so you will always have N
Related Posts Related Posts :
  • Why is this merge sort implementation not giving the correct answer?
  • Applying Filtering to a list which Removes Items
  • Delete substring between delimiters in python
  • Can ImageMagick be packaged with python program? How to do it?
  • Failing to import module named 'version' because izip_longest
  • UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 0: invalid start byte error in python while reading
  • How to apply multiple masks to a dataframe at the same time?
  • Printing longest subsequence of letters using Python
  • Find total from groupby.size() command
  • How to scrape a restricted webpage using Python
  • Converting text file into json in a specific format ( python )
  • Compare multiple images based on pixel values
  • Accessing a nested class from another nested dataclass
  • Print only even number using lambda and map functions
  • Parsing XML: Python ElementTree, find elements and its parent elements without other elements in same parent
  • Taking a list and printing all of the indexes of the elements that aren't equal to 0
  • UnboundLocalError: local variable 'di' referenced before assignment
  • How to convert JSON string with "" (instead of ") to JSON in Python
  • Equivalent of `const` reference to private class members in Python
  • Can't import tensorflow.keras in VS Code
  • How to uniquely copy values in dictionary, in list of dictionaries?
  • Outlier prediction with categorical data in Pythons Scikit-Learn lib
  • Django - Create related object on first call
  • How to use Hashlib to MD5 hash a number?
  • Flask-Toastr installation
  • How to validate a class attribute in python?
  • how to trim the dataframe using ranks in python and reshape them in a new dataframe
  • How do I sort the a list, ascending, by the date?
  • How to add a constant column with maximum value in a pyspark dataframe without grouping by
  • How to plot data in background of multiple subplots in matplotlib
  • Why is the dictionary i created out of another dictionary using a for loop smaller?
  • How to display image stored in Google Cloud bucket
  • How to check when BigQuery query result returns zero records?
  • How to fix `ResolvePackageNotFound` error when creating Conda environment?
  • Splitting a sentence where lower case and upper case are joint
  • Feature comparison between npm, pip, pipenv and poetry package managers
  • How to run a bash script through pycharm?
  • Can Python language be the fastest language in future?
  • How can I find rows in a pandas dataframe where value of col1 for row_x == value of col2 for row_y?
  • python black and white image detection
  • Split dataframe by rows and generate list of dataframes in python
  • Getting an error when trying to use the <= operator for two variables
  • Given a overlayed image (A^B) and one original image (A), how to calculate the other original image (B)
  • Remove "." and "\" from a string
  • How do I make this function able to use a numpy array as an argument and return an array in python?
  • Best way (performance-wise) to iterate over a dictionary
  • Execution time difference with and without a generator in Python3
  • Cannot use numpy with Spark
  • Why this is not working? ploting split outputs with matplotlib
  • Itertools without repetition and order
  • What is the difference between spacy.lang.en and load('en')?
  • How to get Twitter bio information with Tweepy
  • Permutations with repetitions?
  • How to make python ignore an object for garbage collection?
  • How to convert Lambda from Octave to Python
  • What does "model.trainable = False" mean in Keras?
  • Looking to return all possible rolls of two dice. The return value is a list which contains tuples
  • Looping through two arrays and adding the collection of each into new array without dups
  • Pandas dataframe average for each row conditional on dates
  • How to read a particular field from json data?
  • shadow
    Privacy Policy - Terms - Contact Us © 35dp-dentalpractice.co.uk