Message Boards Message Boards

0
|
4360 Views
|
6 Replies
|
3 Total Likes
View groups...
Share
Share this post:

How do I access the add_offset and scale_factor in an .nc file?

Posted 1 year ago

When I give

Import["H:\\g15e\\nc_ecmwf\\era5\\ec_2006010904z_25_PV_T_u_v.nc", \
"Attributes"] [file name works - loses underscores in post]

among the responses are

"/u" -> <|"_FillValue" -> -32767, "add_offset" -> 30.6164, 
  "long_name" -> "U component of wind", "missing_value" -> -32767, 
  "scale_factor" -> 0.00198886, "standard_name" -> "eastward_wind", 
  "units" -> "m s**-1"|>,

How do I access addoffset and scalefactor for subsequent calculations and where is this written up in the online documentation?​

POSTED BY: Joel Tenenbaum
6 Replies
Posted 1 year ago

Look up the documentation for Association.

POSTED BY: Eric Rimbey
Posted 1 year ago

I don't get that message running that code. I get that message if I provide a symbol as the Do iterator and the symbol doesn't evaluate to a number. Is this the exact code, or did you try to simplify the example? I would need to more about what happened in your session. Have you tried quitting the kernel and trying again?

FWIW, you shouldn't expect that code to actually resolve to any value. Well, more accurately it should evaluate to Null.

POSTED BY: Eric Rimbey
Posted 1 year ago

Ah. The problem is that you're using an invalid variable name. The underscore character in Mathematica is used as a shortcut for Pattern. When you did this:

index_a = 0

you actually created a replacement rule for expressions that have a as their head. That doesn't really have anything to do with the iteration variable in Do, because Do will localize that automatically. Still, Do expects a symbol as the iteration variable, not a Pattern expression.

To fix both of these issues, choose a variable name that doesn't include reserved characters.

Having said that, I notice that these error messages are different than what you reported before, so we still haven't figured out what was going wrong before.

POSTED BY: Eric Rimbey

Eric, DId so and thanks.

Going on, why does the following Do line on a 2-d array, array1

 array1 = {{11, 12, 13, 14}, {21, 22, 23, 24}}

  Do[Part[array1, 1, index3], {index3, {1, 2}}]

give an error message to the effect that

  Do::nliter: Non-list iterator index3 at position 2 does not evaluate to a real numeric value.  It seems like a normal Do loop in MM syntax.

Joel

POSTED BY: Joel Tenenbaum

Eric,

I started with a clean fresh notebook and tried with and without initializing the index variable. What is attached is the complete notebook, test05.nb.

Joel

Attachments:
POSTED BY: Joel Tenenbaum

Thanks, and have made progress.

Joel

POSTED BY: Joel Tenenbaum
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract