[MITgcm-support] Barotropic ocean gyre tutorial

Jeremy Miller jeremysharonmiller at gmail.com
Sun Apr 4 02:02:12 EDT 2021


Thank you Jeff. As I wrote in my response to Jan, that didn't resolve the
problem. Moreover, reading in the bin file as type 'float32' as per your
suggestion gave me back an array with all entries being 'inf' and the
penultimate column being '0'.
 I am attaching my script to make things clear.
Would it be possible to attach that python script in an email that you
mention? I could not find it there.
Best
Jeremy

On Thu, 1 Apr 2021 at 23:59, Jeffery R Scott <jscott at mit.edu> wrote:

> Hi Jeremy,
>
> As Jan responded, MITgcm requires big endian files, which the byteswap
> statement accomplishes.
> (the other way to do this : data.astype('>f4').tofile('data.bin’) forces
> python to write out the field in big endian, as mentioned in manual section
> 3.9)
>
> When you write out a file in big endian, you also need to tell python to
> read it back in big endian format:
>
> tau_2_1 = np.fromfile('windx_siny.bin',dtype=‘>f4’)
>
> (you might then also want to reshape it)
>
> This is why when you read in field tau2_1 without telling python it is big
> endian, it doesn’t match your tau2 field.
>
> However, I believe the reason your run is failing using the sine profile
> is different: as configured, the model expects single precision aka float32
> files.
> (MITgcm default for namelist parm readBinaryPrec
> <http://mitgcm.org/lxr/ident/MITgcm?_i=readBinaryPrec> is 32, i.e.
> float32; this can be changed in file data)
> The cosine profile file in github is float32, and this works for you.
> However it looks like you are writing the sine profile file out as float64.
>
> Incidentally, I’ve written a python gendata.py for this tutorial, and
> better still, a carefully documented python script to compute and display
> some output
> for tutorial baroclinic gyre, which you might find very helpful. These
> will hopefully be merged soon into the main github repository, but for
> now can be found in this pull request:
> https://github.com/MITgcm/MITgcm/pull/386
>
> Jeff
>
>
>
>
> But if you write a file
>
> On Apr 1, 2021, at 9:47 AM, Jan Klaus Rieck <jan.rieck at mail.mcgill.ca>
> wrote:
>
> Hello Jeremy Miller,
>
> I also use python to to generate input data for the MITgcm. I found that,
> to generate files that can be read by the MITgcm consistently, I needed to
> specify the type explicitly.
> My way of saving the files would look like this in your case:
>
> if sys.byteorder == 'little': tau_2.byteswap(True)
> fid = open(''windx_siny.bin', 'wb')
> tau_2.astype('float32').tofile(fid)
>
> Of course, 'float32' could be replaced by 'float64' if you require double
> precision.
>
> I hope this helps,
> Jan Rieck
>
> On Thu, 2021-04-01 at 10:22 +0300, Jeremy Miller wrote:
>
> Dear MITGCM forum,
>
> I am Jeremy Miller, I am new to MITgcm and I've been going through the
> tutorials. I have a question about the "Barotropic Ocean Gyre" tutorial
> (section 4.1).
>
> I managed to compile and run the code, and re-produce the first two plots
> shown in section 4.1.5 for  wind stress of τ = τ0 cos( πy/Ly), for both the
> advection and non-advection cases (with the provided input binary files).
> I ran into problems when trying to produce the third plot, for the case
> where τ = τ0 sin( πy/Ly). I am a python user, so I translated gendata.m
> into python to write the input binary files 'windx_cosy.bin'
> 'windx_siny.bin' (see the file gendata_tut4.1py attached).  As explained in
> section 3.9 I've included the snippet
>
> if sys.byteorder == 'little': tau_2.byteswap(True)
>
> where "tau2" is the array to be output. There was no issue in the cosine
> wind stress, and I managed to reproduce the results that I got with the
> original 'windx_cosy.bin' provided in the tutorial. However, with the sine
> wind stress case, the output in 'Eta.0000077760.001.001' is all zeros.
>
> When I attempt to read  'windx_siny.bin' with python into a new array
> called tau2_1. I get absurdly big numbers back, which do not match the
> original array tau2 that I created. If I Remove the snippet " if
> sys.byteorder == 'little': tau_2.byteswap(True) ", in the python gendata
> code, tau2_1 and tau2 match. But, then when I run the code again, the
> file output.txt contains a long list of NaNs.
>
> I have also included the python code used to generate the plots in the
> file tut_4.1_plots.py
>
> Look forward to hearing from you.
> Yours sincerely
> Jeremy Miller
>
> _______________________________________________
>
> MITgcm-support mailing list
>
> MITgcm-support at mitgcm.org
>
>
> http://mailman.mitgcm.org/mailman/listinfo/mitgcm-support
>
>
> _______________________________________________
> MITgcm-support mailing list
> MITgcm-support at mitgcm.org
> http://mailman.mitgcm.org/mailman/listinfo/mitgcm-support
>
>
> _______________________________________________
> MITgcm-support mailing list
> MITgcm-support at mitgcm.org
> http://mailman.mitgcm.org/mailman/listinfo/mitgcm-support
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.mitgcm.org/pipermail/mitgcm-support/attachments/20210404/436df75e/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: gendata_tut4.1.py
Type: text/x-python
Size: 1310 bytes
Desc: not available
URL: <http://mailman.mitgcm.org/pipermail/mitgcm-support/attachments/20210404/436df75e/attachment-0001.py>


More information about the MITgcm-support mailing list