<div dir="ltr">Dear Oliver,<div><br></div><div>Thanks for coming back to me. I did just that. I now get a plot for "eta" that appears to be two sets of constant values, on the left and right of the line x=0.6*1e6 m (see the attached plot in fig_bar_gyre_windx_siny.png). I also notice that the output bin file (tau_2_1) still shows different values to the original numpy array (tau_2). I have attached the latest version of the python script used to generate the data (<a href="http://gendata_tut4.1.py">gendata_tut4.1.py</a>) and the script used to generate the plots (<a href="http://tut_4.1_plots.py">tut_4.1_plots.py</a>).</div><div><br></div><div>Best</div><div>Jeremy</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sun, 4 Apr 2021 at 13:48, Oliver Jahn <<a href="mailto:jahn@mit.edu">jahn@mit.edu</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Hi Jeremy,<br>
<br>
this will not work:<br>
<br>
> if sys.byteorder == 'little': tau_2.byteswap(True)<br>
> fid = open('windx_siny.bin', 'wb')<br>
> tau_2.astype('float32').tofile(fid)<br>
<br>
Can you instead try Jeff's suggestion:<br>
<br>
tau_2.astype('>f4').tofile('windx_siny.bin')<br>
<br>
and NOT use the byteswap command?  Mixing byteswap and astype is a bad<br>
idea as byteswap will create a mismatch between the data in memory and<br>
numpy's assumption of the data type.<br>
<br>
Best,<br>
Oliver<br>
<br>
<br>
> as you suggested, the plot still came out blank.<br>
> Regarding Jeffrey Scott's comment that the reason I could not read back<br>
> the bin file was due to a mismatch between float32 and float64, I<br>
> followed his advice and read in the<br>
> bin file using the snippet <br>
> <br>
> tau_2_1 = np.fromfile('windx_siny.bin',dtype='float32')<br>
> <br>
> and I got back an array with every entry being 'inf' except the<br>
> penultimate column, being all '0'.<br>
> <br>
> Is it possible that the snippet <br>
> <br>
> # X=X.astype('float128')<br>
> # Y=Y.astype('float128')<br>
> <br>
> (which is commented) needs to be included but with 'float128' replaced<br>
> with 'float32'?<br>
> <br>
> Best<br>
> Jeremy<br>
> <br>
> <br>
> <br>
> <br>
> <br>
> On Thu, 1 Apr 2021 at 16:47, Jan Klaus Rieck <<a href="mailto:jan.rieck@mail.mcgill.ca" target="_blank">jan.rieck@mail.mcgill.ca</a><br>
> <mailto:<a href="mailto:jan.rieck@mail.mcgill.ca" target="_blank">jan.rieck@mail.mcgill.ca</a>>> wrote:<br>
> <br>
>     Hello Jeremy Miller,<br>
> <br>
>     I also use python to to generate input data for the MITgcm. I found<br>
>     that, to generate files that can be read by the MITgcm consistently,<br>
>     I needed to specify the type explicitly. <br>
>     My way of saving the files would look like this in your case: <br>
> <br>
>     if sys.byteorder == 'little': tau_2.byteswap(True)<br>
>     fid = open(''windx_siny.bin', 'wb')<br>
>     tau_2.astype('float32').tofile(fid)<br>
> <br>
>     Of course, 'float32' could be replaced by 'float64' if you require<br>
>     double precision.<br>
> <br>
>     I hope this helps,<br>
>     Jan Rieck<br>
>      <br>
>     On Thu, 2021-04-01 at 10:22 +0300, Jeremy Miller wrote:<br>
>>     Dear MITGCM forum,<br>
>><br>
>>     I am Jeremy Miller, I am new to MITgcm and I've been going through<br>
>>     the tutorials. I have a question about the "Barotropic Ocean Gyre"<br>
>>     tutorial (section 4.1).<br>
>><br>
>>     I managed to compile and run the code, and re-produce the first<br>
>>     two plots shown in section 4.1.5 for  wind stress of τ = τ0 cos(<br>
>>     πy/Ly), for both the advection and non-advection cases (with the<br>
>>     provided input binary files). <br>
>>     I ran into problems when trying to produce the third plot, for the<br>
>>     case where τ = τ0 sin( πy/Ly). I am a python user, so I translated<br>
>>     gendata.m into python to write the input binary<br>
>>     files 'windx_cosy.bin' 'windx_siny.bin' (see the file<br>
>>     gendata_tut4.1py attached).  As explained in section 3.9 I've<br>
>>     included the snippet <br>
>><br>
>>     if sys.byteorder == 'little': tau_2.byteswap(True)<br>
>><br>
>>     where "tau2" is the array to be output. There was no issue in the<br>
>>     cosine wind stress, and I managed to reproduce the results that I<br>
>>     got with the original 'windx_cosy.bin' provided in the tutorial.<br>
>>     However, with the sine wind stress case, the output in<br>
>>     'Eta.0000077760.001.001' is all zeros. <br>
>><br>
>>     When I attempt to read  'windx_siny.bin' with python into a new<br>
>>     array called tau2_1. I get absurdly big numbers back, which do not<br>
>>     match the original array tau2 that I created. If I Remove the<br>
>>     snippet " if sys.byteorder == 'little': tau_2.byteswap(True) ", in<br>
>>     the python gendata code, tau2_1 and tau2 match. But, then when I<br>
>>     run the code again, the file output.txt contains a long list of NaNs.<br>
>><br>
>>     I have also included the python code used to generate the plots in<br>
>>     the file <a href="http://tut_4.1_plots.py" rel="noreferrer" target="_blank">tut_4.1_plots.py</a> <<a href="http://tut_4.1_plots.py/" rel="noreferrer" target="_blank">http://tut_4.1_plots.py/</a>><br>
>><br>
>>     Look forward to hearing from you.<br>
>>     Yours sincerely<br>
>>     Jeremy Miller<br>
>>     _______________________________________________<br>
>>     MITgcm-support mailing list<br>
>>     <a href="mailto:MITgcm-support@mitgcm.org" target="_blank">MITgcm-support@mitgcm.org</a><br>
>>     <mailto:<a href="mailto:MITgcm-support@mitgcm.org" target="_blank">MITgcm-support@mitgcm.org</a>><br>
>><br>
>>     <a href="http://mailman.mitgcm.org/mailman/listinfo/mitgcm-support" rel="noreferrer" target="_blank">http://mailman.mitgcm.org/mailman/listinfo/mitgcm-support</a><br>
>><br>
>     _______________________________________________<br>
>     MITgcm-support mailing list<br>
>     <a href="mailto:MITgcm-support@mitgcm.org" target="_blank">MITgcm-support@mitgcm.org</a> <mailto:<a href="mailto:MITgcm-support@mitgcm.org" target="_blank">MITgcm-support@mitgcm.org</a>><br>
>     <a href="http://mailman.mitgcm.org/mailman/listinfo/mitgcm-support" rel="noreferrer" target="_blank">http://mailman.mitgcm.org/mailman/listinfo/mitgcm-support</a><br>
> <br>
> <br>
> _______________________________________________<br>
> MITgcm-support mailing list<br>
> <a href="mailto:MITgcm-support@mitgcm.org" target="_blank">MITgcm-support@mitgcm.org</a><br>
> <a href="http://mailman.mitgcm.org/mailman/listinfo/mitgcm-support" rel="noreferrer" target="_blank">http://mailman.mitgcm.org/mailman/listinfo/mitgcm-support</a><br>
> <br>
_______________________________________________<br>
MITgcm-support mailing list<br>
<a href="mailto:MITgcm-support@mitgcm.org" target="_blank">MITgcm-support@mitgcm.org</a><br>
<a href="http://mailman.mitgcm.org/mailman/listinfo/mitgcm-support" rel="noreferrer" target="_blank">http://mailman.mitgcm.org/mailman/listinfo/mitgcm-support</a><br>
</blockquote></div>