data-exp-lab / yt_xarray

An interface for yt and xarray
MIT License
3 stars 2 forks source link

BUG: longitude range normalization #85

Closed chrishavlin closed 5 months ago

chrishavlin commented 7 months ago

loading a dataset with longitude from 0, 360 causes problems... yt expects -180, 180 and yt_xarray should do some normalizing without copying the data.

chrishavlin commented 5 months ago

hmm, can't actually reproduce this, going to close for now.

import numpy as np
import xarray as xr
import yt_xarray 
import yt_xarray.sample_data
import yt 

ds = yt_xarray.sample_data.load_random_xr_data(
        fields = {'field1': ('altitude', 'latitude', 'longitude')}, 
        dims = {'latitude': (-90,90,30), 
                'longitude': (0, 360, 40), 
                # 'longitude': (-180,180, 40), 
                'altitude': (0, 2000, 20)})

lons = ds.longitude.to_numpy()
lons = np.repeat(lons[np.newaxis, :], len(ds.latitude), axis=0)
lons = np.repeat(lons[np.newaxis,:, :], len(ds.altitude), axis=0)
lons.shape 

da_lons = xr.DataArray(lons, dims=('altitude', 'latitude', 'longitude'))
ds['lonvals'] = da_lons

ds_yt = ds.yt.load_grid()
fname = 'lonvals'
slc = yt.SlicePlot(ds_yt, 'altitude', fname, window_size=(4,2))
slc.set_log(fname, False)

AMRGridData_Slice_altitude_lonvals