OpenDrift / opendrift

Open source framework for ocean trajectory modelling
https://opendrift.github.io
GNU General Public License v2.0
249 stars 120 forks source link

Pixelsize from not projected models #470

Closed arian-dialectaquiz closed 3 years ago

arian-dialectaquiz commented 3 years ago

Hello, my name is Arian Dialectaquiz and I'm I am an undergraduate student in the laboratory I am a part of (Laboratory of Coastal Hydrodynamics of the University of São Paulo - LHiCo -USP), and yesterday I ended up making a pull request instead of an issue, I apologize. However, the difficulty I am facing - for which any suggestions would be most welcome - is as follows:

We are looking to implement Opendrift as an offline drift model using the Eulerian data from the ECOM model - Estuarine and Coastal Ocean Model.

For this, I created a reader based on roms_native, but I needed to make a modification to the basereader.py so that reader_ECOM_S2Z.py worked the way I wrote it.

In line 242 of the basereader, within the set_buffer_size function, I needed to comment on the division by pixelsize, because in the pixelsize calculation, since the ECOM does not have a projection (self.projected is False), the self.xy2lonlat function uses the values ​​of (x, y) minimum (0.0) and maximum (110.137), and returns the value of 0.

My question is, then, how can i use the values of (x, y) ranging from (0.0) to (110, 137) to build the pixelsize without the basereader understanding it to be from 0º to 137 º latitude and 0º to 110º longitude; or that it doesn't understand and return 0?

I believe that only this modification is missing so that the reader_ECOM_S2Z.py works normally with the master version of the basereader.py, however I was unable to get around this difference within the reader_ECOM_S2Z.py.

I leave the reader_ECOM_S2Z.py code below, in the acceptable txt format: Many thabks in advance. reader_ECOM_S2Z.txt

knutfrode commented 3 years ago

Hi,

The method set_buffer_size utilizes the method pixel_size() to calculate the pixel size: https://github.com/OpenDrift/opendrift/blob/master/opendrift/readers/basereader/variables.py#L217

This works well for unprojected ROMS_native, and should also work well for unprojected ECOM. Can you check your values of xmin, xmax, ymin, ymax, and the output of <reader>.pixel_size()? In ROMS_native xmin, ymin are 0, but it seems you have hardcoded these as 1 in your reader?

arian-dialectaquiz commented 3 years ago

Hello.

xmin and ymin are 0, I fixed them, inside the reader_ECOM, as suggested. ymax is 136 and xmax is 109 as was before. pixelsize is 'None', and if do not comment the L217 in variables.py the error of 'float division by zero' continues.

I'll check again in ROMS_native if I kept some important step out in my adaptation.

knutfrode commented 3 years ago

It seems that you do not set delta_x and delta_y to 1 Does that help? What is the output from >>> print(reader) ?

arian-dialectaquiz commented 3 years ago

Setting delta_x and delta_y to 1 the pixelsize becomes 0 And the output from the print is (figure):

image

arian-dialectaquiz commented 3 years ago

And if I ask to print the pixelsize inside the function def pixel_size, in basereader/variables.py, it shows me the value 0. image

knutfrode commented 3 years ago

Your corners in lon and lat are 0, which is suspicious. Are reader.lon and reader.lat 2D arrays with real values?

arian-dialectaquiz commented 3 years ago

Yes. Are real values and the pixelsize is 0 right after the made of splines (figure 1) image Then, few steps later, the pixelsize becomes None (figure 2) image

arian-dialectaquiz commented 3 years ago

However, I'm thinking that there is something wrong with m net_cdf file from hydrodinamic source. Because when I use another netcdf, to another reader - the one for waves data to stokes drift calculations - the values of pixelsize are right. (figure 1)

image And the cornes lat and lon are also right. (figure 2)

image

The waves file has the same projection of ecom file.

knutfrode commented 3 years ago

The screenshot above shows that the lon- and lat- arrays from ECOM model contain a lot of zeros, which will corrupt the interpolation. Lon and lat have to be defined over the whole domain, whether land or ocean.

arian-dialectaquiz commented 3 years ago

Understood! Thank you so much, I'll try solve this and return with the results as soon as possible.

arian-dialectaquiz commented 3 years ago

Hello. I managed to solve it. Thank you so much for your time and help. Those were truly vital marks and necessary to solve the problem.

knutfrode commented 3 years ago

Very good. Then closing this issue for now.